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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.