drupal image upload programmaticaly i am using drupal 7 . and i am trying to upload image progrmatically .. here is my code

$image = file_get_contents('http://drupal.org/files/issues/druplicon_2.png'); // string
$file = file_save_data($image, 'public://druplicon.png',FILE_EXISTS_REPLACE);
print_r($file); exit


and here is my output

stdClass Object
(
    [fid] =&gt; 4
    [uri] =&gt; public://druplicon.png
    [filename] =&gt; druplicon.png
    [filemime] =&gt; image/png
    [uid] =&gt; 1
    [status] =&gt; 1
    [timestamp] =&gt; 1378142542
    [filesize] =&gt; 0
)


now here filesize is 0 . as file doesnot contain any data.  i am working on local m/c.  here is no issue of permission. 
Does anybody tell me how to solve this 

Thanks
The ability for file_get_contents() to fetch contents from an HTTP server depends on the allow_url_fopen parameter in php.ini

If it's not set, $image will be false and saving this leads to an empty file.

You may use Drupal's system_retrieve_file() instead. It's a wrapper on top of drupal_http_request() that comes with its own HTTP client implementation.

Example:

$file = system_retrieve_file('http://drupal.org/files/issues/druplicon_2.png',
                             'public://druplicon.png', false,  FILE_EXISTS_REPLACE);