0
if(empty($nodevalue->field_beachesimages)){
    $imageurl=array(explode(",",$nodevalue->field_beach_migrateurlhidden[$nodevalue->language]['0']['value']));
    foreach ($imageurl as $imagechange) {
        $countimagurl=count($imagechange);
        if($countimagurl>10)
            $imgdata=9;
        else
            $imgdata=$countimagurl;
        for($i=0;$i<$imgdata;$i++){              
           $image =$imagechange[$i];
           $file = system_retrieve_file($image,'public://beachesmigration/', TRUE, $replace = FILE_EXISTS_REPLACE);
           echo "<pre>";print_r($file);echo "</pre>"; exit;
           file_save($file);
           file_usage_add($file, 'iks_beaches', 'beaches', $file->fid);
        }
    }     
}
1

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

0

Try this :

function savefile($filepath, $uid = 1) {
  global $base_url;
  if (filesize($filepath) == 0 ) {
    return array();
 }
  $file = (object) array(
    'uid' => $uid,
    'uri' => $filepath,
    'filemime' => file_get_mimetype($filepath),
    'status' => 1,
  );
  if(file_exists($filepath)) {
    $file = file_copy($file, 'public://');   //Change path here
    return $file;
  } else {
    return array();
  }
}



$file = savefile("http://wordpress.ikitesurf.com/wp-content/uploads/2012/09/2032239599_fdce5e0ab0_z.jpg");
  • Hello. Yuor answer does not mention $pathval or beachesmigration, so how it is supposed to help? – Mołot Aug 26 '13 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.