File name fields and dupliacate files
7 posts
• Page 1 of 1
File name fields and dupliacate filesI have a field of widget type "File Name" with the allowed extensions set to a single value (i.e. pdf). I have observed that if I create a new record and upload a file with a name that already exists on the server, '-1' is appended to the whole filename. So for example 'myfile.pdf' gets uploaded as 'myfile.pdf-1'. I appreciate that this is to stop files being inadvertently overwritten, but wouldn't it be more sensible to upload it as 'myfile-1.pdf' thus keeping the proper file extension?
Re: File name fields and dupliacate filesOn a related note to this question, has anyone developed an elegant way to retain -original- file names when uploading the files to the filesystem and not the database? I'd like to keep files on filesystem rather than database, but currently the filename is changed if a duplicate file already exists. This isn't great, because we'd like to be able to have database remember what the original uploaded file name was!
For instance, if I have a file fridge-1.pdf and upload it, later I won't know for sure if its name was really fridge-1.pdf or it was changed from fridge.pdf to fridge-1.pdf. As a hack, I am thinking of having an additional field called "FileName" and letting user type in file name. Thanks!
Re: File name fields and dupliacate filesUse your strategy of adding a filename field but make it hidden and auto fill it with a before save trigger using the name of the uploaded file.
Re: File name fields and dupliacate filesGood suggestion! With that suggestion, I wonder what will happen if the user re-edits the row in the table.
We probably would want the trigger to be only activated if a new file is uploaded or the file is changed, but not to be triggered if a file remains the same. Otherwise the "good" filename could be overwritten by the "bad" internal filename after a 2nd save.
Re: File name fields and dupliacate files
Re: File name fields and dupliacate filesThanks! This got me started, but it needed to be modified as it would clear the value in the hidden form if I re-saved the table row without uploading a new file.
Here is code that worked for me:
7 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 25 guests |