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);
}
}
}
-
what is the problem in the above code? Are u getting any errors? Pls mention – harshal Aug 26 '13 at 6:02
-
i use the above code but no folder creation takes place :( – Ajmal Aug 27 '13 at 8:53
-
You can use drupal_mkdir() to create new folder in the code above Link : api.drupal.org/api/drupal/includes!file.inc/function/… – harshal Aug 27 '13 at 9:01
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);
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
orbeachesmigration
, so how it is supposed to help? – Mołot Aug 26 '13 at 7:00