I've got a hundred or so files (mixed types: pdf, ppt, doc, etc). I want to be able to upload these to my server, and then point my D7 site to the directory on the server that contains all of these files so that the site automatically creates a node for each file, with a single, different file attached to each node. Is there a module that will do this for me?
Using Bulk File Nodes you can create unlimited number of nodes at once .
Bulk File Nodes allows a user to upload or import many files at once, and have many individual nodes created, one for each file . Where this module significantly differentiates from other modules like Bulk Media Upload is that after uploading/importing the file(s), the user is given the opportunity to edit all of the fields for each node in a single form.
This module creates a node for each file and you can edit the fields of each node after uploading.
You are right, Bulk File Nodes works only with images. since you need to create nodes programmatically and assign the files to the nodes you can use the following code to create a node without a file field
$uid = SOME_USER_UID $values = array( 'type' => 'THE_CONTENT_TYPE', 'uid' => $uid, 'status' => 0, 'comment' => 0, 'promote' => 0, 'language' => 'en' ); $entity = entity_create ('node', $values); $ewrapper = entity_metadata_wrapper('node', $entity); $ewrapper->title->set('THE_TITLE'); $ewrapper->save();
But from Attaching image files to nodes programmatically in Drupal 7 you can use the following code to attach the file to the above node
$filepath = drupal_realpath('misc/druplicon.png'); // Create managed File object and associate with Image field. $file = (object) array( 'uid' => 1, 'uri' => $filepath, 'filemime' => file_get_mimetype($filepath), 'status' => 1, ); // We save the file to the root of the files directory. $file = file_copy($file, 'public://'); $ewrapper ->field_file[LANGUAGE_NONE] = (array)$file;
This code should be above
You can also create the nodes without file fields as described above. and for each node with
$node variable Programmatically Attach Files to Node.
// We have complete file path. $file_path = '/whatever/path/to/file/sample.pdf'; $file = new stdClass; $file->uid = $node->uid; $file->filename = pathinfo($file_path, PATHINFO_BASENAME); $file->uri = $file_path; $file->filemime = file_get_mimetype($file_path); // Make it permanent, otherwise it will get deleted later. $file->status = FILE_STATUS_PERMANENT; // Save file object to make it a 'managed file'. file_save($file); // We will save file under this location. $destination = 'public://PDFs/'; // Make sure destination directory exists before moving files to that path. // This will create directory if it does not exists. file_prepare_directory($destination, FILE_CREATE_DIRECTORY); // Now attach file to the file field. $node->field_pdf[$node->language] = (array) $file; // Default file type field comes with this extra properties. $node->field_pdf[$node->language]['display'] = 1; $node->field_pdf[$node->language]['description'] = 'Our special PDF'; // Save node to make the attachment effective. node_save($node);