Dumping all user uploads into the base "files" directory is difficult to manage. It's hard to see who's done what, when, how, etc. And as there's no "uid" field in the uploads table, it's not immediately obvious how to tell who uploaded a given file.
This patch is one idea for better managing files uploaded with the upload module. If enabled, it saves uploads into a subdir that is a filsystem-safe version of the user's name. (ie, if user "joe cool" uploads file "test.txt", it ends up in "files/joe_cool/test.txt").
(I've added this functionality to my site based on feedback from users of my site.)
This could easily be made configurable per role, instead of as a global option.
Comments
Comment #1
(not verified) commentedusernames can change. perhaps uid is a better choice
Comment #2
jeremy commentedLooks like I previewed the patch away. (Perhaps the project module could use the upload module to handle file uploads? This would gain it the ability to handle multiple uploads, and would prevent it from forgetting about uploads when one presses "preview").
Anyway, the patch is now attached.
Comment #3
jeremy commented"usernames can change. perhaps uid is a better choice"
Perhaps. But if this was done, I'd still want it displayed to the user as their username (as this was the request from users on my site). Perhaps aliasing could be used much the same way the upload module displays the permanent path when previewing an uploaded file.
Comment #4
dries commentedAdding a uid-column to the files-table sounds like a better solution. Other modules, like the workspace module, could take advantage of that.
Comment #5
killes@www.drop.org commentedI agree with Dries.
Comment #6
sami_k commentedThis patch is 4.5, but something similar would be great for 4.7, as was discussed at OSCMS, anyone else interested?
Comment #7
sami_k commentedHere's the patch updated for 4.7
Comment #8
sami_k commentedBTW, as per Dries recommendation it now uses uid and dumps the files under uid/$user->uid.
Comment #9
sami_k commentedUpdated the name of the patch.
Comment #10
sami_k commentedI was testing the code and it seems to still need work... changed status.
Comment #11
sami_k commentedOkay, fixed it up a bit and I want some review on it... Saves files to the user/$uid directory.
Comment #12
sami_k commentedThe above patch applies cleanly to HEAD.
Comment #13
Veggieryan commentedhey there,
applied the 4.7b5 patch and all went well..
it looks to be working.. the file is uploaded to the user/uid directory..
but the link comes up "page not found"
see http://remixer.org/node/4
this is because I am using "private" file system in the admin>>settings
if i change to public it works fine..
can we get this working with private file system?
thanks
ryan.
ps... also.. can we integrate with this patch?
http://drupal.org/node/42358
Comment #14
sami_k commentedDries and chx are on that so that will most likely end up in core if the patcher cleans up his work, this stuff is on the side... They have not looked at this thread in like a year... So it makes no point for me to go over and try to incorporate that work into this. I will look into the problem with the private file system, thanks!
Comment #15
sami_k commentedmarked back to code needs work until i can get the private file issue sorted out.
Comment #16
dopry commented@samik,
what is the status of this guy? Do you want me to get it going again? I'm a fan of files by uid relationships... even if it is late for 4.7...
Comment #17
sami_k commentedif you have time, sure the current problem is listed above. it doesn't work with private files. it does work otherwise.
Comment #18
dopry commentedWhat issues are you having with private files, what debugging/integration have you done to date?
Comment #19
sami_k commentedI essentially ported the old patch to 4.7 after reviewing the code. In terms of debugging, I have not gone through any rigorous process to ensure that this patch is fully functional. It's not that comlex of a patch at all. It simply appendings the output out of a function to the folder the file is being stored in.
Comment #20
killes@www.drop.org commentedmoving to cvs
Comment #21
dopry commentedThis could probably be revisited using the token.module. There is a patch to add a uid column to files as well at
http://drupal.org/node/115267.
Comment #22
Crell commentedAt least for Drupal 5, this is now solved by a contrib: http://drupal.org/project/uploadpath
If token module were to make it into core, merging upload path into core would make sense. Until then, it happily lives in contrib-land.
Comment #23
sami_k commentedComment #24
drewish commentedthis won't be happening in 6. but there is a uid on {files} now.
Comment #25
webchickIf I am not mistaken, once #652306: Regression: Add back token support for files is fixed, this will be possible, since token /is/, in fact, now in core. Along with File module. Hooray!
Marking as won't fix, since upload module will never be getting this feature.