Hello,
Lets imagine I have a file called a.pdf and I edit it by uploading b.pdf.
Should the final file on the server be name a.pdf or b.pdf? Instinctively I think the normal behavior is to remove a.pdf and place b.pdf on the server.
However, it is simply renames b.pdf to a.pdf and overrides the original file.
The addition of the "Keep original filename" button only adds to the confusion because, either way the final final will always have the name of the initial file.
The problem seems to be on line 838 of file_entity.pages.inc where, if the extension is the same, it simply file_unmanaged_copies to the original file path.
I've forced this if to always be false solving what I really think to be a bug.
You can test this behavior using https://simplytest.me.
Additionally, I think a redirect should be created from a.pdf to b.pdf after the file is changed. I didnt by using hook_file_update on a separate module.
Comments
Comment #2
joseph.olstadAre you selecting the option 'keep the same filename' ?
#2958574: Enforce stricter "Keep Original Filename" option for same extensions
Comment #3
jdearie commentedI seem to be having the same issue.
I have a file titled a.pdf
I replace it with a file title b.pdf
The filename is overwritten as a.pdf but is the new b.pdf content
The same action occurs whether I check the Keep Original Filename box or not.
I also tried using the patch at https://www.drupal.org/project/file_entity/issues/2958574, but it seems to be fixing what I'm hoping happens - meaning I want the filename to be changed to the filename of the newly uploaded file UNLESS the Keep Original Filename box is checked.
I'm on 7.x-2.21
Comment #4
joseph.olstadHi jdearie, thanks for reporting. I believe there is an existing patch that will resolve this.
please try this RTBC patch #2958574: Enforce stricter "Keep Original Filename" option for same extensions
https://www.drupal.org/files/issues/2018-04-04/Change_filename_when_repl...
if it works for you, please report your findings in 2958574.
Your feedback is valuable and will help greatly for the next release.
Comment #5
joseph.olstadactually, I'll leave this open as a support request until confirmation of results.
Comment #6
jdearie commentedinstalled the patch and it worked for me!
I uploaded a PDF (a.pdf) into Content > Files. Then edited its entity, and under "Replace file", uploaded a different file named "b.pdf", checked "Keep original filename", select the file, and saved. It saved as "a,pdf" but had the contents of "b.pdf".
If I unchecked "Keep original filename", when uploading it had "b.pdf" as the filename.
One thing to note - if your users don't change the Name field of the file entity (when using the media browser from WYSIWYG to upload a file), then the file entity name may still show the old file name but will still correctly link to the new file name.
cross posted results in 2958574
thx!!
Comment #7
joseph.olstad