apologize every one , my code was correct , I had a mistake in content type .2 similar content type with 2 similar image field :P
but I let it and don't delete this because maybe be useful in futures
I want to save multi image in multi image field programmatically(I set number of value to 5)
Part of my code
$node = new stdClass(); // Create a new node object
$node->type = "prodcut_gift_display"; // Or page, or whatever content type you like
$node->uid = $user->uid;
$uri = file_build_uri($geturipath);
$file = new stdClass;
$file->uid = $user->uid;
$file->filename = basename($uri);
$file->uri = $uri;
$file->filemime = file_get_mimetype($uri);
$file->filesize = filesize($mainimg_url);
$file->status = 1;
file_save($file);
$node->field_gift_image['und'][0] =(array) $file;
/***************************************/
foreach ($upimg_uri_path as $inx=>$upimgtemp){
unset($file);
$uri = file_build_uri($upimgtemp);
$file = new stdClass;
$file->uid = $user->uid;
$file->filename = basename($uri);
$file->uri = $uri;
$file->filemime = file_get_mimetype($uri);
// $file->filesize = filesize($mainimg_url);
$file->status = 1;
file_save($file);
$node->field_gift_image['und'][$inx+1]=(array) $file;
}
/***************************************/
Then I try to get drupal_json_output
, it seems node and image field with 2 value is ok but only one value saved in field.where is the problem?(I check and sure that my image field is set multi and can get 5 value )
update Also I try
$uri = file_build_uri($geturipath);
$imgs_paths[]=file_create_url($uri);
/***************************************/
foreach ($upimg_uri_path as $inx=>$upimgtemp){
unset($file);
$uri = file_build_uri($upimgtemp);
$imgs_paths[]=file_create_url($uri);
}
foreach ($imgs_paths as $i=>$img) {
$file_info = system_retrieve_file($img, 'public://pictures/', TRUE, FILE_EXISTS_REPLACE); //storing image inside picture folder
if ($file_info->fid) {//if fid exist then image is saved from URL.
$node->field_gift_image['und'][$i]['fid'] = $file_info->fid; //assign image
}
}
/***************************************/
$node->field_product['und'][0]['product_id'] = $my_prodcut->product_id;
$node->title = arg(1) . '-' . rand(1, 999999);
$node->language = 'fa';
$node = node_submit($node);
node_save($node);
Also my field settings