Closed (won't fix)
Project:
FileField
Version:
6.x-3.7
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 Aug 2010 at 20:57 UTC
Updated:
6 Dec 2010 at 02:22 UTC
I can't imagine that this hasn't been done before, but we are having trouble accomplishing it. We're using Windows Live Writer to post a blog node through XML-RPC. When this is uploaded, we try to identify the images, strip them out, and add them to a cck filefield. It posts fine, but when you try to edit the post, it won't save. Can anyone see anything wrong with our code:
preg_match_all('/<img[^>]+>/i',$node->body, $result);
$img = array();
foreach( $result as $img_tag=>$img_tag_str)
{
preg_match_all('/(src)=("[^"]*")/i',$img_tag_str[0], $img[$img_tag]);
}
foreach($img[0][0] as $imgstr) {
$imgstring = $imgstr;
break;
}
// explode this now
$imgnamearr = explode("/", $imgstring) ;
//get last array element
$imgname = $imgnamearr[count($imgnamearr) -1 ];
//remove " character from the last of the string
$imgname = substr( $imgname, 0 , strlen( $imgname )-1 );
global $user;
$mime = 'image/jpeg';
$file_drupal_path = "sites/files/$imgname";
print 'yyy'. $file_drupal_path;
$file = new stdClass();
$file->filename = basename($file_drupal_path);
$file->filepath = $file_drupal_path;
$file->filemime = $mime;
$file->filesize = filesize($file_drupal_path);
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$file->fid = db_result(db_query("SELECT fid FROM {blogapi_files} WHERE filepath = '%s'", $file->filepath));
$nid = $node->nid; // your NID here
$node->field_img = array(
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,
),
Comments
Comment #1
quicksketchUnfortunately I'm unable to help with custom code in the FileField queue. As there haven't been any responses, I'm closing this issue directly.