2

I am interested in making a 'physical' folder structure to match a hierarchy I create through content types.

My hierarchy currently exists in the format

-Container
--folder
---presentation

and I want to create a folder structure when each level is created that mimics this, so that would be

[container_name]
[container_name]/[folder_name]
[container_name]/[folder_name]/[presentation_name]

I've been trying to use the drupal_mkdir() function within a module of my own creation which uses hook_node_insert, but I am a little too 'green' to know exactly what to do.

2

The method I used to solve this was that in my Drupal site I had entity references at each level that connected me all the way down to my root. It was a simple process of using the functions such as node_load() to return information about the entity and its title, which I was then able to concatenate into a string of text like is in the example above: container_name]/[folder_name]/[presentation_name] After that I was able to simply use this code to build the folder after each node was submitted:

//$path contained the remaining file path to be built
$dirpath=variable_get('file_public_path', conf_path() . '/files');
drupal_mkdir("$dirpath/$path");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.