I am trying to download many files from an external server (about 3700 images). These images go from 30 KB to 200 KB each.
When I use the copy() function on 1 image, it works. When I use it in a loop, all I get is 30B images (files with empty images).
I tried using copy , cURL , wget and file_get_contents . Every time I get a lot of empty files or nothing at all.
Here are the codes I tried:
Wget:
exec('wget http://mediaserver.centris.ca/media.ashx?id=ADD4B9DD110633DDDB2C5A2D10&t=pi&f=I -O SIA/8605283.jpg');
Copy:
if(copy($donnees['PhotoURL'], $filetocheck)) { echo 'Photo '.$filetocheck.' updated<br/>'; }
Curl:
$ch = curl_init(); $source = $data[PhotoURL]; curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec ($ch); curl_close ($ch); $destination = $newfile; $file = fopen($destination, "w+"); fputs($file, $data); fclose($file);
Nothing seems to work. Unfortunately, I don't have much choice to download all of these files at once, and I need a way to get it working as soon as possible.
Thanks a lot Antoine
source share