Menu Close

Upload Image From URL in PHP

0
(0)

Let’s see  how to upload image from the URL in PHP.

It is very simple to upload image from URL to server.

Here, you have to enter the complete URL including image name and clicking on upload button then image will upload to server.

Upload Image From URL using PHP.

Create a HTML form to submit an image URL

<!DOCTYPE html>
<html>
    <body>
        <form method="POST">
            <input type="text" name="image_url" placeholder="Enter image url">
            <input type="submit" name="upload_image" value="Upload">
        </form> 
    </body>
</html> 

PHP snippet to upload an image to server on the form submission.

<?php
if(isset($_POST['upload_image'])) {
    $src_image =   file_get_contents(filter_input(INPUT_POST, "image_url"));
    $new_info = "images/new.jpg";
    $status = file_put_contents($new_info, $src_image);
    if($status){
        echo '<img src="images/new.jpg">';   
    } else {
        echo "not uploaded";    
    }
}
?> 

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Share

Posted in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

You can also read...