$name = basename($file); // Build the file object $file_obj = new stdClass(); $file_obj->filename = $name; $file_obj->filepath = $file; $file_obj->filemime = 'text/plain'; $file_obj->filesize = $filesize; // You can change this to the UID you want $file_obj->uid = $uid; $file_obj->status = FILE_STATUS_TEMPORARY; $file_obj->timestamp = time(); $file_obj->list = 1; $file_obj->new = true; // Save file to files table drupal_write_record('files', $file_obj); // change file status to permanent file_set_status($file_obj, 1); // Attach the file object to your node XXX create/attach to comment? $issue->files[$file_obj->fid] = $file_obj; } } upload_save($issue); // Mark it private. It'd be nice if this could be wrapped in a transaction // with above node_save. //if ($private) { //db_query("UPDATE {node_access},{private} SET gid='$uid', realm='private_author', grant_view='1', grant_update='1', grant_delete='1', private='1' WHERE {node_access}.nid='$nid' AND {private}.nid={node_access}.nid"); //db_query("UPDATE {private} SET private='1' WHERE nid='$nid')"); //} // Now that everything is privatized and such, send notifications project_mail_notify($nid); print "OK {$nid} http://www.virtualmin.com/node/{$nid}\n";
<?php $active = FLASE; if ($active) { # upload files $nid = $node->nid; $uploads = array(); foreach ($files as $file) { $upl = new StdClass(); $upl->fid = 'upload'; $upl->filename = $file['dest_path']; $upl->filepath = $file['src_path']; $upload->filemime = 'image/jpeg'; $upl->filesize = $file['size']; //$upl->description = $file[1]; $upl->list = 1; array_push($uploads, $upl); } $node->files = $uploads; upload_save($node); # save image fields $files = $node->files; $images = array(); foreach ($files as $file) { array_push($images, array('title' => $file->filename, 'nid' => $nid, 'fid' => $file->fid)); } $node->field_diaporama = $images; node_save($node); }