Image upload from url in php

In this Article,I will explain how to upload image from url using php.I have written simple script using php functions to upload image from another domain.

Example: Image upload to URL.
<?php
display_errors(0);
$url = "http://www.example.com/logo.jpg";
$file_name= substr($url, strrpos($url,"/")+1, 
strlen($url)-strrpos($url,"/"));  //Retrive file name from url
$img = file_get_contents($url);//get contents of file
$f = fopen($file_name, 'w');//Open file
fwrite($f, $img);//Write File
fclose($f);  
?>

I hope above script will help you to upload image from URL in php.

Cheers :)