Solved

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

Posted on 2009-05-13
4
341 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
4 Comments
 
LVL 10

Assisted Solution

by:Tyler Laczko
Tyler Laczko earned 50 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 100 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 100 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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