increase Posted May 14, 2022 Share Posted May 14, 2022 I want to backup mp3 files from a server folder to a local folder can this be done in php which is server side. I tried many scripts claiming to do this but all result in 'failed to open stream: No such file or directory' because the code is looking for the destination on the server, not the local directory. Here is an example that says it can be done. ini_set('display_errors',1); error_reporting(E_ALL); $source = "https://domain.com/2024-2021/path_to_file/test.mp3"; echo "src is ", $source; $destination = "C:/backup/2024-2021/Cpath_to_file/"; file_put_contents($destination, file_get_contents($source)); echo "OK"; This one also claims to 'force' the download $file = '/path/to/files/photo.jpg'; if (is_file($file)) { sendHeaders($file, 'image/jpeg', 'My picture.jpg'); $chunkSize = 1024 * 1024; $handle = fopen($file, 'rb'); while (!feof($handle)) { $buffer = fread($handle, $chunkSize); echo $buffer; ob_flush(); flush(); } fclose($handle); exit; } But has the same problem, in that it fails when opening the local folder to write the file, is there a way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/314791-downloading-files-from-server-to-local-folder-in-php/ Share on other sites More sharing options...
kicken Posted May 14, 2022 Share Posted May 14, 2022 A remote server will not have access to your local file system, so no you cannot have your remote PHP script copy files to your local system. Quote Link to comment https://forums.phpfreaks.com/topic/314791-downloading-files-from-server-to-local-folder-in-php/#findComment-1596245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.