Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Every picture that's uploaded for any user gets the name "picture-.jpg", which means successive user pictures overwrite each other.
Attached patch adds the user ID into the picture name.
Comment | File | Size | Author |
---|---|---|---|
user-picture-upload.patch | 546 bytes | Eric Scouten | |
Comments
Comment #1
JonBob CreditAttribution: JonBob commentedI can't check this easily, because I don't use this feature, but...
The file upload system is supposed to ensure that files never overwrite one another, by appending numbers to the end of file names when necessary to avoid collisions. Is this happening in this case? If so, there is no bug; if not, the bug is probably in file.inc and should not be worked around in user.module IMO.
Comment #2
Eric Scouten CreditAttribution: Eric Scouten commentedNo, in my case, the file_save_upload function is dying when it can't overwrite the existing file. (Due to the way I do backups, etc., the image files get set to read-only. You could argue that having things be read-only is a problem, but IMHO it shouldn't even be *attempting* to write to the existing file.)
Also, in the original version of user.module, there was a clear attempt to include the user's ID number in the picture file name, but this attempt was failing. (See the line immediately following my patch's insertion.)
So it may be the case that there are in fact *two* bugs: one that the file upload system isn't doing collision avoidance as you expected, and two that the user.module isn't appending user IDs as expected. Let's keep this bug open to represent bug #2. Not being super familiar with the file upload system, I'll leave it to someone else (JonBob?) to decide if a separate bug should be filed for #1.
Comment #3
ccourtne CreditAttribution: ccourtne commentedActually there are probably three bugs. As described before the file api will change the filename if it already exists. Unfortunately it will not tell the calling module what it changed the name to. Therefore the user.module will reference the wrong filename and the wrong image will be displayed.
Comment #4
Dries CreditAttribution: Dries commentedCommitted Eric's patch. Thanks. Marking this 'active' rather than 'fixed'.
Comment #5
(not verified) CreditAttribution: commented