Option to upload files to /files/node/[node#]/
AmirTheSeventh - July 24, 2007 - 15:51
| Project: | IMCE |
| Version: | 5.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Currently the module creates a folder under "/files/" called u[user#] when a user want's to upload a picture, What does it take to add an option to instead create a folder under "/files/node/" called [node#]?
The current methodology is good for small size website with a few users, on a larger site with many users and nodes, it’s much better to keep the node’s files under a directory relative to the node. E.g. user can delete a file in his folder not remembering that he used it on a node, as a result node will miss the file and no one notice it.

#1
I am also looking for something similar to this.
If a image is inserted into the node content then the node should own the file and not the user who inserted it. Anyone with privileges to edit a content type should be able to manage images attached to it also. As said it makes management easier.
One problem I encounter is if User A uploads a file and inserts it into a page User B cannot log in, delete the old image from the disk and replace it with a new one or preview the existing images used in the node uploaded by User A. Also if a user decides to do a tidy up of the files they can delete images still referenced by nodes leading to broken images.
#2
However, if you take this approach then you very well could have the same image/file uploaded multiple times. So, if you need to update that file, you would have to update it on every node that uses that file. I think this would be harder to manage than a broken link. I can find broken links, I can't find when a file is an outdated version.
- Shane
#3
I could see this becoming a problem if a site has a lot of nodes with images (32,000 nodes with images = 32,000 subdirectories). I think a better system might be something like an option to upload to directories based upon yyyy/mm. Even better would be an option under each profile for automatic creation based upon a user defined replacement variables. IE - you could have an option for the directory:
Automatically create directory based on : {yyyy}/{mm}/{nid}
That way the directory tree would be automatically created to the sites liking.
(incidentally - I did manage to get IMCE to automatically put new uploads into subdirectories based upon the yyyy/mm format, but could never get the Javascript to show the proper directory. You end up having to do a bunch of refreshes to get it going.)
EDIT:
On second thought the NID idea wouldn't work. If you are doing a fresh post you don't have a NID, so there wouldn't be anything there.
#4
True, but there are ways around this problem. For example, the core upload.module adds an entry in the {files} table on file upload, saving the file info in the {sessions} table until it can add a row to the {upload} table on node insert or update (using nodeapi) that includes the nid and vid. Directories that incorporate nids could also use the session to keep track of a file before the nid is available, saving the file to a temporary location until the node is known and then copying it into the node-specific files directory. The WYSIWYG editor would need to manage the file paths before and after the nid is known in order to make the image show up while editing but that should be possible since the editor is creating the img src value.
I agree about the proliferation of node-specific directories, but a lot of Drupal sites also have more than 32,000 users.