Upload Image From Url Using PHP

Upload Image From Url Using PHP

Uploading is now-a-days a kind of hobby and we also want to save our memories so today i have an image uploader for you this image uploader will upload image by url only.


Good day programmers today we are going to build Upload Image From Url Using Php. As you know the HTML markup is necessary for that so we should have some HTML markup first . Below is the code provided and you have to save it with the filename as provided.



Save It As index.html :

<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/shoelace-css/1.0.0-beta9/shoelace.css"/>
</head>
<body>
<center>
<form method="post" style="width:60%;margin:20%;" action="php/upload.php">
<h2>Upload Image From URL Using PHP</h2><br>
<input type="text" name="img_url" placeholder="Enter Image URL"><br>
<input type="submit" class="button" name="get_image" value="Submit">
<a class="button" href="https://softwebtuts.blogspot.com">For More Tutorials Visit SoftwebTuts</a>
</form>
</center>
</body>
</html>


I cannot provide you demo because i am using blogger and blogger does not support php so you can try this code provided below on your localhost server or on your website.


Uploading is now-a-days a kind of hobby and we also want to save our memories so today i have an image uploader for you this image uploader will upload image by url only.


So here is the php functions and files that you will need for this project you can copy the code or simple download archive from the download link below which contains all the files used in this project.

<?php
if(isset($_POST['get_image'])) // Run Function When Button Is Clicked
{
$url=$_POST['img_url']; // Get image URL
$data = file_get_contents($url);
$time = date("h-i-s-a"); // Get time
if (!file_exists('../images')) {
mkdir('../images', 0777, true); // function to check if directory doesn't exist create it
}
$new = '../images/image-'.$time.'.jpg'; // Save Image
file_put_contents($new, $data);
echo "<img src='".$new."'>"; // Output Image
}
?>




Closure :

We are done and our project Upload Image From Url Using Php is ready now you can save all the files as provided.
Copy Paste and Run that's it



Download Project (Upload Image From Url Using Php) File :

Upload Image From Url Using Php.zip
File Size 1.06 KB
Click the download button above and your download will be started in few ( 10 ) seconds. If your download does not start automatically then click Download Started Button Above to download it manually.


So guys this post is completed and if you want anything else right here you can also comment that topic I will try to make a post about it you can take a while for that.



Thank you !


M.Muzammil

I am Muzammil, a Self-taught Web Designer & Developer. I haven't yet completed my college degree. Started learning programming at the age of 12 and still learning. I love to work in Javascript and make eye-catchy designs. Free for your calls :)

Post a Comment

Feel free to leave your positive feedback in the comments section below.

Previous Post Next Post