【发布时间】:2013-05-08 10:59:12
【问题描述】:
我正在编写这个 PHP 脚本,用于将工资存根导入 Drupal。它按照我想要的方式做所有事情,除了脚本没有将上传的 PDF 文件附加到节点。
一些笔记; Drupal 的文件系统设置为私有,不确定这是否有所不同。其次,pdf文件已经在正确的位置'paystubs/[uid]/paystub_1.pdf'所以我认为我的问题是文件没有正确关联到节点。
这里是代码
function create_drupal_node($employeeID, $employeeDate, $drupalUid, $file2) {
$sourcePDF = "/var/www/html/mgldev.************.com/burst_pdfs/pdfs/" . $file2;
$destinationPDF = '/paystubs/' . $drupalUid . '/' . $file2;
$destination = '/paystubs/' . $drupalUid . '/';
if (!file_check_directory($destination, TRUE)){
echo "Failed to check dir, does it exist?";
mkdir($destination);
echo "trying to drupal mkdir...";
}
// Copy the file to the Drupal files directory
if (file_exists($sourcePDF)) {
if(!rename($sourcePDF, $destinationPDF)) {
echo "Failed to move file\n";
}
}
//Create node and attach file uplaod
$file_drupal_path = "paystubs/" . $drupalUid . "/" . $file2;
$mime = 'pdf/application';
$file = new stdClass();
$file->filename = $file2;
$file->filepath = $file_drupal_path;
$file->filemime = $mime;
$file->filesize = filesize($file_drupal_path);
$file->uid = $drupalUid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$node = new StdClass();
$node->type = 'paystub';
$node->body = $employeeID;
$node->title = $employeeDate;
$node->field_paystub_upload = array(
array(
'fid' => $file->fid,
'title' => $file2,
'filename' => $file->filename,
'filepath' => $file->filepath,
'filesize' => $file->filesize,
'mimetype' => $mime,
'data' => array(
'description' => $file2,
),
'list' => 1,
),
);
$node->uid = $drupalUid;
$node->status = 1;
$node->active = 1;
$node->promote = 1;
node_save($node);
}
节点已创建并且节点的标题和正文具有正确的值。当我使用 Devel 模块查看节点时,我可以看到“field_paystub_upload”数组为空。因此,出于某种原因,除了将文件附加到节点之外,它所做的一切都是正确的,这就是我几天来一直在努力的事情。最好的反应是免费上网?
【问题讨论】:
标签: php drupal drupal-6 file upload