Download & save a remote image on your server using PHP

In this tutorial of Php Tutorials for Beginners we will show you how to download and save images from remote server to your server.
To download and save images from remote server to your server we need 2 php file functions.

1 - file_get_contents()
This function is the used to read the contents of a file into a string.
Syntax:-
file_get_contents("URL")
Here URL is path of file to read.

2 - file_put_contents()
This function is the used to writes a string to a file.
Syntax:-
file_put_contents(file,data,mode,context)
Here file and data are required fields.

Example:-
$image = file_get_contents('http://www.any_url.com/image.jpg');
file_put_contents('/images/new_image_name.jpg', $image); //save the image on your server
Hope this php tutorial is useful for you. Keep following Php Point for more Codes.

No comments:

Post a Comment