News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Simple PHP script save remote images to local server

Started by Ride, August 15, 2005, 12:38:07 PM

Previous topic - Next topic

Ride

I need a simple script that I can put in my crontab that will go to the specified url (for example http://www.somesite.com/images/aphoto.jpg) and download the image to a folder on my server (and overwrite the old one).  I already have the permission of the site owners so there's no issue of "stealing" their content.  I've been searching google but haven't found something yet.  I'm sure it's really easy.  Thanks!

Ride

ok, I found and got this script to work.  Now, how can I do this for multiple url's?  Do I need to create a script for each remote file or can I have 1 script that does 'em all? 

<?php
$remote 
fopen("http://www.awebsite.com/livecams/borderline/borderline_big.jpg""rb");
$local fopen("/path/to/public_html/ridesocal/cams/cam.jpg""wb");

// Copy data from remote to local
while (!feof($remote)) {
    
$data fread($remote1024);
    
fwrite($local$data);
}

fclose($local);
fclose($remote);
?>


By the way, does the above code look good?  No possible loops or anything right?  I'm getting this error in the error logs when I run it...

[15-Aug-2005 11:17:33] PHP Warning:  Unknown(): Unable to load dynamic library './ffmpeg.so' - ./ffmpeg.so: cannot open shared object file: No such file or directory in Unknown on line 0


Doesn't make any sense to me

Anguz

You can put that code in a function and have a list of URLs in an array that you'll loop and call the function for each.
Cristián Lávaque http://cristianlavaque.com

Ride

Quote from: Anguz on August 15, 2005, 07:13:16 PM
You can put that code in a function and have a list of URLs in an array that you'll loop and call the function for each.

Can you show an example?  Also, any idea on that error I'm getting?

Anguz

Well, I don't know about the error, but the thing I mentioned is pretty simple actually. I didn't test it at all, though, so I may be absolutely wrong, but I'd give it a go with something like this:


$urllist = file('urllist.txt');

foreach ($urllist as $url)
image_import($url);


where image_import() is the code you have, with a few modifications to figure out the filename from the URL to store locally, or generate a new name.
Cristián Lávaque http://cristianlavaque.com

Advertisement: