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

quicksketch’s picture

There 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.

obrienmd’s picture

Actually, 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?

quicksketch’s picture

I'd suggest looking at FileField Sources, since it can directly transfer files from URLs on the node edit form.

obrienmd’s picture

OK, 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!

quicksketch’s picture

Status: Active » Fixed

This 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.

obrienmd’s picture

Agreed, thanks quicksketch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.