Log in

View Full Version : call php function in image url download



eyeshield21
08-17-2007, 04:18 AM
Hey well i need help i want to create a simple image downloading script
where you insert the image URL and it will download it and place it on
the server, Any one have any ideas on how i can do this?


eg...

http://www.weberdev.com/UserPictures/NoImage.jpg


http://www.weberdev.com/UserPictures/NoImage.jpg


thanks

djr33
08-17-2007, 05:56 PM
If your PHP setup is configured to allow remote files, this should work for you:

<?php
$i = file_get_contents('http://...../image.jpg');
$f = fopen('path/my.jpg','w+');
fwrite($f,$i);
fclose($f);
?>

eyeshield21
08-19-2007, 05:21 PM
I need to create a simple image downloading script where you insert the image URL and it will download or add it and place it on the server or in the database, Any one have any bright ideas on how i can do this?

eg:

The image of 39dollarglasses.com (http://www.39dollarglasses.com/store/images/thumb/2164_Brown.jpg), in which i will insert it to my website using php script.. i really appreciate your help.. thanks in advance..

djr33
08-19-2007, 07:28 PM
$i = file_get_contents($_GET['url']);

Then just make a form with a field "url" and that will be the url used in the script, or you could link to it like "thatpage.php?url=http://whatever".

You may want to use error checking, with
if (file_exists($_GET['url'])) first
etc.

As for adding to a database, etc., look here:
http://php-mysql-tutorial.com