// Формируется картинка
if(isset($product_data->Картинка)){
// Занесение картинки в
$file = new stdClass();
$file->filename = (string)$product_data->Картинка;
$path_source = $path .'/'.$file->filename;
if(file_exists($path_source)){
$node->field_image_cache = array();
$path_destanation = file_create_path().'/'.$file->filename;
if(!file_exists($path_destanation) && file_check_directory(dirname($path_destanation), true)){
//$path_destanation = file_destination($path_destanation, FILE_EXISTS_REPLACE);
file_copy($path_source, $path_destanation, TRUE);
if($path_source){
$file->filepath = $path_destanation;
$info = image_get_info($path_destanation);
$file->filemime = $info['mime_type'];
$file->filesize = $info['file_size'];
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$_file = array();
foreach($file as $name=>$option){
$_file[$name] = $option;
}
$node->field_image_cache[] = $_file;
}
}else{
$file->filepath = $path_destanation;
$info = image_get_info($path_destanation);
$file->filemime = $info['mime_type'];
$file->filesize = $info['file_size'];
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$_file = array();
foreach($file as $name=>$option){
$_file[$name] = $option;
}
$node->field_image_cache[] = $_file;
}
[user=unlink]unlink[/user]($path .'/'.$file->filename);
}
}
if(isset($product_data->Картинка)){
// Занесение картинки в
$file = new stdClass();
$file->filename = (string)$product_data->Картинка;
$path_source = $path .'/'.$file->filename;
if(file_exists($path_source)){
$node->field_image_cache = array();
$path_destanation = file_create_path().'/'.$file->filename;
if(!file_exists($path_destanation) && file_check_directory(dirname($path_destanation), true)){
//$path_destanation = file_destination($path_destanation, FILE_EXISTS_REPLACE);
file_copy($path_source, $path_destanation, TRUE);
if($path_source){
$file->filepath = $path_destanation;
$info = image_get_info($path_destanation);
$file->filemime = $info['mime_type'];
$file->filesize = $info['file_size'];
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$_file = array();
foreach($file as $name=>$option){
$_file[$name] = $option;
}
$node->field_image_cache[] = $_file;
}
}else{
$file->filepath = $path_destanation;
$info = image_get_info($path_destanation);
$file->filemime = $info['mime_type'];
$file->filesize = $info['file_size'];
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$_file = array();
foreach($file as $name=>$option){
$_file[$name] = $option;
}
$node->field_image_cache[] = $_file;
}
[user=unlink]unlink[/user]($path .'/'.$file->filename);
}
}
Комментарии
Потом же опять будешь говорить "Верните мои статьи!"
Зачем столько кода?
Вооружаемся drupal_execute, вот так можно сохранить imagefield поле.
<?php
$imagefield = content_fields($field_name, $content_type);
$imagefield_validators = imagefield_widget_upload_validators($imagefield);
if ($image_file = field_file_save_file($image_path, $imagefield_validators, file_directory_path())) {
$form_state['values'][$field_name][] = array('fid' => $image_file['fid']);
}
?>
RxB пусть висит, это я его спрашивал