Upload Image From URL in PHP

Published on 19th Feb 2018 in PHP

In this tutorial we will see how to upload image from URL in PHP. It is very easy to upload image from url to server.In this example, you have to pass complete image path including image name and clicking on upload button will upload image to server.

This is very simple explanation about upload image from URL to server in PHP.

 Upload Image From URL in PHP


Ajax image upload with jQuery and PHP

Upload Multiple Images with jQuery and PHP


First create a HTML form to enter an image URL.

<form method="POST">
	<input type="text" name="image_url">
	<input type="submit" value="Upload" name="upload_image">


Write php snippet to upload image to server on form submission.

	if(isset($_POST['upload_image'])) {
	       //read a file from source
		$src_image =	file_get_contents(filter_input(INPUT_POST, "image_url"));
		//give new file name
		$new_info = "images/new_image.jpg";
		//write data to a file
		$status = file_put_contents($new_info, $src_image);
		echo '<img src="images/new_image.jpg">';	
		} else
		echo "not uploaded";	

You can also upload any doc file to server using above steps. This example demonstrate about how to upload an image file from URL to server in PHP.

Share It
Stay Connected
Like Us on Facebook