How to get the image from the url and store in the custom path? if(empty($nodevalue-&gt;field_beachesimages)){
    $imageurl=array(explode(",",$nodevalue-&gt;field_beach_migrateurlhidden[$nodevalue-&gt;language]['0']['value']));
    foreach ($imageurl as $imagechange) {
        $countimagurl=count($imagechange);
        if($countimagurl&gt;10)
            $imgdata=9;
        else
            $imgdata=$countimagurl;
        for($i=0;$i&lt;$imgdata;$i++){              
           $image =$imagechange[$i];
           $file = system_retrieve_file($image,'public://beachesmigration/', TRUE, $replace = FILE_EXISTS_REPLACE);
           echo "&lt;pre&gt;";print_r($file);echo "&lt;/pre&gt;"; exit;
           file_save($file);
           file_usage_add($file, 'iks_beaches', 'beaches', $file-&gt;fid);
        }
    }     
}
Hope this will help you.

In Drupal 7 , system_retrieve_file function will download a file from a remote source, copy it from temp to a specified destination and optionally save it to the file_managed table if you want it to be managed.


You need to create a folder beachesmigration inside sites\default\files.
By using system_retrieve_file it will be store your images inside beachesmigration folder with the filename you no need to specify the filename manually.



 $image = 'http://wordpress.ikitesurf.com/wp-content/uploads/2012/09/2032239599_fdce5e0ab0_z.jpg';
//I have used picture folder to store images using image field settings
 $file = system_retrieve_file($image, 'public://beachesmigration/', TRUE, $replace = FILE_EXISTS_REPLACE);



Source