How to programatically add attachments to a user (securely) To any Drupal 7 gurus out there... I have hundreds of PDFs that need to be uploaded to users as their own private attachment. I've created the PDFs in the folder:-

../website-files/userfiles-{uid}/filename.pdf  (There's one for each uid)

My field_data_field_attachments table has the "field_attachments_fid" column with the id relating to the file_managed table.

This is all pretty self explanatory, until... I find the file_managed table has two mysterious columns:-


  __pk
   __unique_uri


Both seem to be MD5 checksums, e.g:- 


  4A448458-860C-4E16-B901-F8841136C17D


So my question is; how do I correctly generate these two values for each attachment I import to the DB?

Thanks,
Darren
You want to try and use the drupal api to move these files into drupal. Since you talk about private files, I assume you've enabled a private filesystem ... or else this discussion is pointless as all your files with be public :).

Once you've done that you could take your hundreds of files and put them in your server someplace and use file_move to place them into the drupal private filesystem using a small php script.

A module tutorial with a private file upload widget can be seen at this blog post and uses the drupal api to store a private file. Private files typically use hook_file_download which that blog post also shows to allow access to the file.