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

Anonymous’s picture

usernames can change. perhaps uid is a better choice

jeremy’s picture

StatusFileSize
new4.57 KB

Looks 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.

jeremy’s picture

"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.

dries’s picture

Adding a uid-column to the files-table sounds like a better solution. Other modules, like the workspace module, could take advantage of that.

killes@www.drop.org’s picture

I agree with Dries.

sami_k’s picture

This patch is 4.5, but something similar would be great for 4.7, as was discussed at OSCMS, anyone else interested?

sami_k’s picture

Version: » 4.7.0-beta5
Assigned: Unassigned » sami_k
Status: Active » Needs review
StatusFileSize
new5.35 KB

Here's the patch updated for 4.7

sami_k’s picture

BTW, as per Dries recommendation it now uses uid and dumps the files under uid/$user->uid.

sami_k’s picture

Title: upload into subdir based on user's name » upload into subdir based on uid

Updated the name of the patch.

sami_k’s picture

Status: Needs review » Needs work

I was testing the code and it seems to still need work... changed status.

sami_k’s picture

Status: Needs work » Needs review
StatusFileSize
new5.04 KB

Okay, fixed it up a bit and I want some review on it... Saves files to the user/$uid directory.

sami_k’s picture

The above patch applies cleanly to HEAD.

Veggieryan’s picture

hey 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

sami_k’s picture

Dries 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!

sami_k’s picture

Status: Needs review » Needs work

marked back to code needs work until i can get the private file issue sorted out.

dopry’s picture

@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...

sami_k’s picture

if you have time, sure the current problem is listed above. it doesn't work with private files. it does work otherwise.

dopry’s picture

What issues are you having with private files, what debugging/integration have you done to date?

sami_k’s picture

I 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.

killes@www.drop.org’s picture

Version: 4.7.0-beta5 » x.y.z

moving to cvs

dopry’s picture

Version: x.y.z » 6.x-dev

This 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.

Crell’s picture

At 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.

sami_k’s picture

Assigned: sami_k » Unassigned
drewish’s picture

Version: 6.x-dev » 7.x-dev

this won't be happening in 6. but there is a uid on {files} now.

webchick’s picture

Status: Needs work » Closed (won't fix)

If 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.