php - Drupal 6 Programmatically adding an image to a FileField -


how programmatically add image file field? have url/filepath of image wish upload. have tried following:

$newnode->field_profile_image[0]['value'] = 'http://www.mysite.com/default.gif'; 

but not seem work.

i have tried:

$newnode->field_profile_image[0]['value'] = 'sites/default/files/default.gif';

the file not need external webiste. happy have anywhere on site in question.

you're going have use hook_nodeapi set correctly. you're going want modify under "insert" operation. make sure resave node after you've added required fields.

drupal wants map image entry in file table, setting url not work. first off, if it's remote file, can use function listed in brightcove module on line 176, brightcove_remote_image, grab image , move local directory.

once remote image moved place, need save files table , configure node's property. i've done in method:

////// in nodeapi /////     case "insert":         $node->field_image[0] = _mymod_create_filearray($image_url);         node_save($node); 

this writes files record, , returns formatted image array.

///// mymod_create_filearray ///// function _mymod_create_filearray($remote_url){   if ($file_temp = brightcove_remote_image($remote_url)) {     $file = new stdclass();     $file->filename = basename($file_temp);     $file->filepath = $file_temp;     $file->filemime = file_get_mimetype($file_temp);     $file->filesize = filesize($file_temp);      $file->uid = $uid;     $file->status = file_status_permanent;     $file->timestamp = time();     drupal_write_record('files', $file);      $file = array(      'fid' => $file->fid,       'title' => basename($file->filename),       'filename' => $file->filename,       'filepath' => $file->filepath,       'filesize' => $file->filesize,       'mimetype' => $mime,       'description' => basename($file->filename),       'list' => 1,     );     return $file;   }   else {     return array();   } } 

and should it. let me know if have questions.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -