![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/ |
<?php
// Download and store Adagio for Strings audio file locally
require_once 'config/database.php';
$pdo = getDBConnection();
// Find Adagio track
$stmt = $pdo->prepare("SELECT * FROM music_tracks WHERE title LIKE '%Adagio%' AND task_id = '9bf0fc77de4c62243425086e8ff1763e'");
$stmt->execute();
$track = $stmt->fetch();
if (!$track) {
die("Track not found!");
}
echo "<h1>Download Adagio for Strings Audio File</h1>";
echo "<p><strong>Track:</strong> {$track['title']}</p>";
echo "<p><strong>Task ID:</strong> {$track['task_id']}</p>";
echo "<p><strong>Current Audio URL:</strong> " . htmlspecialchars($track['audio_url']) . "</p>";
$audioUrl = $track['audio_url'];
$taskId = $track['task_id'];
if (empty($audioUrl) || empty($taskId)) {
die("Missing audio URL or task ID!");
}
// Check if it's already a local file
if (strpos($audioUrl, '/audio_files/') === 0) {
$localPath = '.' . $audioUrl;
if (file_exists($localPath)) {
echo "<p style='color: green; font-weight: bold;'>✅ Audio file already stored locally: {$audioUrl}</p>";
echo "<p>File size: " . number_format(filesize($localPath)) . " bytes</p>";
exit;
}
}
// Create audio directory if needed
$audioDir = 'audio_files/';
if (!is_dir($audioDir)) {
mkdir($audioDir, 0755, true);
echo "<p style='color: green;'>✅ Created audio directory</p>";
}
// Generate local filename
$extension = pathinfo(parse_url($audioUrl, PHP_URL_PATH), PATHINFO_EXTENSION) ?: 'mp3';
$filename = "{$taskId}.{$extension}";
$localPath = $audioDir . $filename;
$webPath = '/audio_files/' . $filename;
// Check if file already exists
if (file_exists($localPath)) {
echo "<p style='color: green;'>✅ File already exists locally: {$webPath}</p>";
echo "<p>File size: " . number_format(filesize($localPath)) . " bytes</p>";
// Update database to use local path
$updateStmt = $pdo->prepare("UPDATE music_tracks SET audio_url = ? WHERE id = ?");
if ($updateStmt->execute([$webPath, $track['id']])) {
echo "<p style='color: green; font-weight: bold;'>✅ Updated database to use local file!</p>";
}
exit;
}
// Download the file
echo "<p>📥 Downloading audio from: " . htmlspecialchars($audioUrl) . "</p>";
$context = stream_context_create([
'http' => [
'timeout' => 300,
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'follow_location' => true
]
]);
$audioContent = @file_get_contents($audioUrl, false, $context);
if ($audioContent === false) {
echo "<p style='color: red;'>❌ Failed to download audio file!</p>";
echo "<p>Error: " . error_get_last()['message'] . "</p>";
exit;
}
$fileSize = strlen($audioContent);
echo "<p>✅ Downloaded {$fileSize} bytes</p>";
// Save the file
if (file_put_contents($localPath, $audioContent, LOCK_EX)) {
echo "<p style='color: green; font-weight: bold;'>✅ Saved to: {$localPath}</p>";
echo "<p>File size: " . number_format(filesize($localPath)) . " bytes</p>";
// Update database to use local path
$updateStmt = $pdo->prepare("UPDATE music_tracks SET audio_url = ? WHERE id = ?");
if ($updateStmt->execute([$webPath, $track['id']])) {
echo "<p style='color: green; font-weight: bold;'>✅ Updated database! Audio URL is now: {$webPath}</p>";
echo "<p><a href='{$webPath}' target='_blank'>Test Audio File</a></p>";
} else {
echo "<p style='color: orange;'>⚠️ File saved but database update failed</p>";
}
} else {
echo "<p style='color: red;'>❌ Failed to save file!</p>";
}
?>