Possible Duplicate:
save image from php url using php
How can i use php to save/grab an image from another domain(not on my domain/server) and save it in a directory of my site.
The URL of the image for example , will be :
http://anothersite/images/goods.jpg
How can i use PHP to grab "good.jpg" ,and save it in my directory which is www.mysite.com/directory/
I hope someone could guide me. Thanks!
The copy() function in PHP is used to copy a file from source to target or destination directory. It makes a copy of the source file to the destination file and if the destination file already exists, it gets overwritten. The copy() function returns true on success and false on failure.
file_put_contents ( $img , file_get_contents ( $url )); echo "File downloaded!" File downloaded! Note: It save the image to the server with given name logo.
php $target_Path = "images/"; $target_Path = $target_Path. basename( $_FILES['userFile']['name'] ); move_uploaded_file( $_FILES['userFile']['tmp_name'], $target_Path ); ?> when the file(image) is saved at the specified path... WHAT if i want to save the file with some desired name....
You should be able to use file_get_contents
for this one. In order to use an URL with file_get_contents
make sure allow_url_fopen
is enabled in you php.ini
file.
define('DIRECTORY', '/home/user/uploads');
$content = file_get_contents('http://anothersite/images/goods.jpg');
file_put_contents(DIRECTORY . '/image.jpg', $content);
Make sure that you have write permission to the directory where you want to store the image; to make the folder writable you could do this:
chmod +w /home/users/uploads
References
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With