Closed (fixed)
Project:
FileField
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
17 Apr 2010 at 02:11 UTC
Updated:
4 May 2010 at 19:50 UTC
I'm fairly familiar with programatically editing nodes using node_load and node_save, or using drupal_execute, but I'm not sure how I'd get this done. I'd like to take a known file from a url, say "http://www.site.com/download?id=5", and have it saved to a filefield entry (the filefield is unlimited, and could have multiple entries already) when I'm editing the node with node_load/node_save in PHP. Any snippets or best practices on how to do this?
Thanks in advance!
Comments
Comment #1
quicksketchThere are a couple of scripts for migrating to FileField in the handbook: http://drupal.org/node/432852.
Ultimately you'll need to transfer the file locally, save it into the database with field_file_save_file(), then set the FID in the $node object and node_save() it.
Comment #2
obrienmd commentedActually, it's not for migration - it's for an interesting workflow: We are using the Fill PDF module, but the user wants the Filled PDF "version" of the node information saved as a filefield for a very specific reason. Thus, when saving the node, I was going to create a rule to save the pdf version (which I can grab from URL, maybe using cURL?) as a filefield.
Any other thoughts?
Comment #3
quicksketchI'd suggest looking at FileField Sources, since it can directly transfer files from URLs on the node edit form.
Comment #4
obrienmd commentedOK, I was able to figure out grabbing a file out of cURL, saving it on the server, adding a record in the files database. However, are there any best practices for adding a cck field record to the "end" of a set of unlimited records? So, if there are 5 files in a filefield currently, this PHP would run to add a 6th.
Thanks so much for the previous responses, they helped me get comfortable with the first few steps of this very quickly!
Comment #5
quicksketchThis is out of scope for the FileField issue queue. I'm happy to help with how FileField is used or point to existing references, but I think you've crossed the point where specialized help can be provided. As such I'm moving this issue to fixed as a support request.
Comment #6
obrienmd commentedAgreed, thanks quicksketch.