I need to save an image from a PHP URL to my PC. Let's say I have a page, http://example.com/image.php
, holding a single "flower" image, nothing else. How can I save this image from the URL with a new name (using PHP)?
Click on the Download Image from URL button, the field will appear on the right. Enter the full web address of the image. Click on the arrow to the right of the field and select the Force Check checkbox. Then click the Save button.
If the server is configured correctly, you cannot download a PHP file. It will be executed when called via the webserver. The only way to see what it does is to gain access to the server via SSH or FTP or some other method.
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.
If you have allow_url_fopen
set to true
:
$url = 'http://example.com/image.php'; $img = '/my/folder/flower.gif'; file_put_contents($img, file_get_contents($url));
Else use cURL:
$ch = curl_init('http://example.com/image.php'); $fp = fopen('/my/folder/flower.gif', 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp);
Use PHP's function copy():
copy('http://example.com/image.php', 'local/folder/flower.jpg');
Note: this requires allow_url_fopen
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