What is the best way to download image files with PHP?

Hi,

I want to download image files which may be as large as 400KB using a PHP script. I don't need to read the file into a string, so I thought a function like file_get_contents() might be memory inefficient.

Would something like shell_exec("wget $image_url") followed by rename() to move the file be more appropriate, or is file_get_contents() fine for this purpose?

Thanks
tomp_glAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ycTINConnect With a Mentor Commented:
copy function is best to do this in php
http://www.php.net/copy
0
 
Tyler LaczkoConnect With a Mentor Commented:
So your copying images from another site to your own.

both will work

wget would be faster
file_get_contents would be easier
0
 
tomp_glAuthor Commented:
Just as a side-note: I am mirroring images from my central server to my edge servers - not ripping content from other sites, if that is what you are implying, I am not sure.
0
 
markh789Connect With a Mentor Commented:
You should use wget for your speed. Also, don't copy just download straight to the spot, use cd to change your current dir then run wget.

Faster then having to move files.
<?php
shell_exec("cd /home/username/public_html/files/.");
shell_exec("wget " . $image_url);
?>

Open in new window

0
All Courses

From novice to tech pro — start learning today.