drupal_execute填充图像字段

发布于 2024-09-15 09:46:09 字数 218 浏览 3 评论 0原文

如何使用drupal_execute填充图像字段值。

例如我的内容类型(测试)有两个附加字段 1. 照片(图像提交), 2. phid (文本字段)

用于 phid $form_state['values']['field_phid'][0]['value'] ='14'; 。如何填充图像字段类型的照片

How to populate image field value with drupal_execute.

for ex my content type (test) has two additional fields
1. photo (image filed),
2. phid (text field)

for phid $form_state['values']['field_phid'][0]['value'] ='14'; . how to populate photo which is image field type

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衬遮猫 2024-09-22 09:46:09

如果文件已经上传到 Drupal 并具有文件 ID (fid),那么您可以执行“

$form_state['values']['field_image_filed'][0]['fid'] = 17; //where 17 is the Drupal file ID of the file you want input

如果文件尚未上传”则要棘手得多。您首先需要以编程方式创建该文件。我无法立即引导您完成它,但寻找有关如何完成的模板的好地方是服务模块的 file_service.inc 中的 file_service_save() 函数:
http://drupalcode.org/viewvc/drupal/contributions/modules/services/services/file_service/file_service.inc?revision=1.1.2.7.2.3&view=markup& ;pathrev=DRUPAL-6--2-2

需要明确的是:我并不是说您将使用 file_service_save() 来完成上传,而是该代码向您展示了需要做什么。它将向您展示如何使用 file_save_data() 将文件保存到服务器,将文件记录到 Drupal“文件”表,然后调用 hook_file_insert 通知其他模块文件已保存。

If the file is already uploaded to Drupal and has a file ID (fid) then you can just do

$form_state['values']['field_image_filed'][0]['fid'] = 17; //where 17 is the Drupal file ID of the file you want input

If the file isn't already uploaded it's a lot trickier. You'll first need to programmatically create the file. I can't walk you through it off-hand but a good place to look for a template as to how it should be done is the file_service_save() function in the Services module's file_service.inc:
http://drupalcode.org/viewvc/drupal/contributions/modules/services/services/file_service/file_service.inc?revision=1.1.2.7.2.3&view=markup&pathrev=DRUPAL-6--2-2

To be clear: I'm not saying you'll use file_service_save() to accomplish the upload, but that that code shows you what needs to be done. It will show you how to save the file to the server using file_save_data(), record the file to the Drupal "files" table, then call hook_file_insert to notify other modules that a file's been saved.

迷离° 2024-09-22 09:46:09

我找到了如下解决方案。我不知道优点和缺点,但它对我来说效果很好。

$image = "*******/test.jpg";
$field = content_fields('field_img', 'img_test');
$validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
$files_path = filefield_widget_file_path($field);
$form_state['values']['field_img'][]= field_file_save_file($image, $validators, $files_path, FILE_EXISTS_REPLACE);

i found the solution as below . i dont know pros and cons but it works fine for me.

$image = "*******/test.jpg";
$field = content_fields('field_img', 'img_test');
$validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
$files_path = filefield_widget_file_path($field);
$form_state['values']['field_img'][]= field_file_save_file($image, $validators, $files_path, FILE_EXISTS_REPLACE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文