I have this image URL (no extension):
https://www.google.com/abc/files/AwAh20isBECxwscp4JiT
How can I save this image in my server folder?
I have this image URL (no extension):
https://www.google.com/abc/files/AwAh20isBECxwscp4JiT
How can I save this image in my server folder?
You can use file_get_contents($url)
in order to retrieve the contents of any remote file if you have allow_url_fopen
enabled in your PHP configuration.
Once you download the image into memory, then you can save it with
file_put_contents($img, $imgcontent)
Example might look like this:
$url = 'https://www.google.com/abc/files/AwAh20isBECxwscp4JiT';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));
If you don't allow remote URLs to be opened by fopen()
, then you have the option of using the cURL
functionality to grab files remotely.
$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);
Duplicate of: Saving image from PHP URL