如何在使用“file_scan_directory”后将文件对象保存到字段
我尝试使用 file_scan_directory 扫描一些文件并获取一些本地路径,我希望它们成为一个对象并保存到数据库中,所以我需要 file_save 来这样做。 file_save 将文件对象作为参数,我怎样才能成功这个过程?
我尝试过file_save_upload,API文档提到参数“$source --- 指定要保存的上传文件的文件路径或URI的字符串。”,但是它似乎不读取路径并且总是返回null。
我还尝试自定义创建一个文件对象供 file_save 运行,它确实有效,但不认为它是正确的 drupal 方式,是否有任何解决方案:
file_scan_directory-> ???? ->文件保存-> field_attach_update(* 文件保存后用新的 fid 更新字段)
请帮忙,非常感谢!
I try to use file_scan_directory to scan some files and get some local path, and I want them to become an object and save into db, so I need file_save to do so.
file_save take an file object as parameter, and how can I suppose to success this procedure?
I have try file_save_upload, API doc mentioned the parameter "$source --- A string specifying the filepath or URI of the uploaded file to save.", however it seems not to read the path and always return null.
I also try to custom create a file object for file_save to run, it does work but don't think it's in correct drupal way, would there be any solution for:
file_scan_directory-> ???? -> file_save -> field_attach_update (* update a field with new fid once the file is save)
please help for this, thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码片段将扫描一些 jpg 文件,保存到数据库中,并将文件附加到字段。
This snippet will scan some jpg files, save into db, and attach the files to a field.