Anybody know any php script witch is can download a file from the internet? I will wanna use with cron...
Asked
Active
Viewed 612 times
0
-
1Why not just use wget or curl from your cron job? If that's not an option, if [allow_url_fopen](http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen) is supported on your host, you can just use [copy](http://www.php.net/manual/en/function.copy.php) – fvu Jan 26 '14 at 23:46
-
Thanks for your quick reply! I not use wget, because I don't know how I can do? How I can do it with wget where I can add an direction where will download that file? – Marcell Nemeth Jan 27 '14 at 00:45
-
use the -P command, see http://stackoverflow.com/questions/1078524/wget-how-to-specify-the-location-with-wget – fvu Jan 27 '14 at 01:40
-
Okay... So command looks like: wget -p /tmp/ http://somesite.com/file.jpg ? – Marcell Nemeth Jan 27 '14 at 01:56
-
that's uppercase P, not lowercase, see [the manual](http://www.gnu.org/software/wget/manual/wget.html). – fvu Jan 28 '14 at 01:51
-
Yes, it is uppercase... Thanks! – Marcell Nemeth Jan 28 '14 at 02:05
2 Answers
2
Well, php might be a little overkill. You can just use
wget http://somesite.com/file.jpg
to grab a file and download it.
If, for some reason, you need to use PHP, you might want to try
$file = file_get_contents('http://somesite.com/file.jpg');

Andrew Clark
- 279
- 1
- 3
-
Thanks for your quick reply! Both solutions are very useful... With the wget, how I can add (direction) where, or what folder I want to download that file? That file will always rewrite per every downloads? With php how I can do that too? – Marcell Nemeth Jan 27 '14 at 00:42
-
so, if you want to save it to a specific directory, add -P, like this: wget http://somesite.com/file.jpg -P /directoryname/ Also, it won't overwrite the file. The default behavior is to add a number to the end of the filename if a file of that name already exists in that directory. – Andrew Clark Jan 27 '14 at 02:56
-
1As for PHP, what I provided only gets the file data. To save it, [use this](http://us1.php.net/file_put_contents). So to continue the example in my original posts, you would do this: file_put_contents('/directoryname/filename.jpg', $file); – Andrew Clark Jan 27 '14 at 03:04
1
Thanks for to the two responders help! I managed to find a solution to my problem. Yeah, do not need to use any php script to download any files from the internet. Is the best, use wget for that:
wget 'http://www.domain.com/dynamic.php?343d6d5gvfegr' -O /folder1/folder2/file.png

Marcell Nemeth
- 97
- 3
- 4
- 13