?
Solved

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

Posted on 2009-05-13
4
Medium Priority
?
345 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:tomp_gl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Assisted Solution

by:Tyler Laczko
Tyler Laczko earned 150 total points
ID: 24380277
So your copying images from another site to your own.

both will work

wget would be faster
file_get_contents would be easier
0
 

Author Comment

by:tomp_gl
ID: 24380373
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
 
LVL 7

Accepted Solution

by:
ycTIN earned 300 total points
ID: 24381281
copy function is best to do this in php
http://www.php.net/copy
0
 
LVL 3

Assisted Solution

by:markh789
markh789 earned 300 total points
ID: 24394480
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question