Very Simple PHP Script to Upload Image or file from an URL!

A very simple PHP Script i have written here. You can see the demo & download the script at the bottom of the post!

How difficult if you want to uplaod a Photo / Image or a PDF from an URL. Do you thing this is so difficult?.

Have you ever used file_get_contents and file_put_contents?. If you don’t you got a chance now to do it!.

If you are a PHP Developer don’t worry!. Here is the simple script will do the trick for you and you can easily understand by reading the comments in the script itself!

See the snippet below (please make sure your folder is writable (permission: 775 or 777)):


// this three lines of code will upload an image from any url to the your folder!

$url = "http://www.theonlytutorials.com/images/logo.png";
$name = basename($url);
file_put_contents("uploads/$name", file_get_contents($url);

For your convenience I have written a small program where you can copy paste or download and use it in your own projects!

 

Secure your ‘uploads’ folder. Learn how to here: http://blog.theonlytutorials.com/learn-prevent-executing-php-file-folder-directory/

Download   Demo

23 Comments

Add a Comment

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