How to save image from URL in server folder using php or javascript?

Jaimes Rodrigues

I have this image URL (no extension): https://www.google.com/abc/files/AwAh20isBECxwscp4JiT

How can I save this image in my server folder?

mike510a

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to save image from url into assets folder

how to upload Image in Blazor server app and save the image in the folder (& in the server) save that url to the db

How to save image from remote server where image extension is missed using PHP

Save image from url to special folder

Save Image to the Designated Folder and Subfolder using PHP?

How to save image url from Firebase storage to realtime databse using javascript?

How can i download image from the url and save it to a local directory using javascript?

How to get image from url and save it in mysql as BLOB ? php

How to Save Image to Application Folder from UIImagePickerController?

How to get and save image to folder from listview

How to upload an image into a folder with blob:http link using PHP and JavaScript?

How to save captured image inside folder using codeigniter (image captured by javascript code)?

How to save data from URL to asset folder?

How to display an image from a folder using PHP variable in a HTML tag?

PHP copy image from url to folder

Save image from url to local System in php

How to save an image in a folder?

How To get Image URL From PHAsset? Is it possible To save Image using PHAsset URL to document Directory?

PHP - save a converted image into a folder

How to save from javascript/jquery dropdown value using php to mysql

How to save an image from website to another server

Save Image in External Storage By using Picasso from Url , how to download image and show it in imageview

How to delete an image from a folder in PHP

Save image locally from url using javascript node.js and fs

how to change link from image url using php

How can I resize an image from URL using PHP?

How to get image from url using meteor / javascript

How to change background image from user input (URL) using JavaScript

How to create an image array from a URL array in JavaScript using map?