我正在使用 CURL 抓取一个文件,并想将它保存在本地,但它插入了 Drupal 的文件系统。我必须手动插入还是有更好的方法?我能找到的最接近的是:
function image_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items);
但是我不知道怎么用这个。有更好的建议吗?
最佳答案
有几种方法,但最简单的方法是使用 file_save_upload()
:
$source = '/path/to/file.ext';
$dest = 'public://uploads/'; // Or whatever
$file = file_save_upload($source, array(), $dest, FILE_EXISTS_RENAME);
if ($file) {
// file_save_upload marks the file as temporary, we need to mark as permanent or it will be cleared from the database in a few hours
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
}
关于drupal - 以编程方式在 Drupal 的文件系统中插入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8874887/