Menu Close

Upload Image From URL in PHP


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>
        <form method="POST">
            <input type="text" name="image_url" placeholder="Enter image url">
            <input type="submit" name="upload_image" value="Upload">

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

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);
        echo '<img src="images/new.jpg">';   
    } else {
        echo "not uploaded";    
Posted in PHP

You can also read...