Jump to content

Best Method For Copying Remote Files


hellonoko

Recommended Posts

I am using the below simple code to copy remote files:

<?php
$copydir = "/home2/sharingi/public_html/scrape/scraped/";

$data = file_get_contents($url);
$file = fopen($copydir . $clean_file_name, "w+");
fputs($file, $data);
fclose($file);
?>

 

However when I am attempting  to copy a certain file. I run into a situation where the file does not load or error for quite some time and so the MySql code after my copy code times out.

 

Warning: file_get_contents(http://www.theliverhearts.com/audio/02%20Local%20Lift.mp3) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home2/sharingi/public_html/scrape/copy.php on line 36
MySQL server has gone away

 

I am wondering what the best way to copy a remote file would be so that I can handle these situations and other file errors.

 

Perhaps CURL?

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/152726-best-method-for-copying-remote-files/
Share on other sites

It's telling you it can't find the file, and if the url used in the queyr there (http://www.theliverhearts.com/audio/02%20Local%20Lift.mp3). The link doesn't work to http://www.theliverhearts.com/audio/02%20Local%20Lift.mp3

 

Mybad, read that too fast and missed the error handling part.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.