Does anyone have a working example of upload retaining original filename and delete file?
Does anyone have a working example of upload retaining original filename and delete file?
I am working to customize the upload example for Editor. I have problems that maybe others have solved:
1) I want to retain the uploaded file name. Now it is 1.png, 2.png etc. I want the uploaded file to retain the orignal filename.
2) I want the attachment file to be deleted when I clear it. Now the file info in DB is cleared but the file still remains on the server.
Here is the example I am trying to customize:
https://editor.datatables.net/examples/advanced/upload.html
This question has accepted answers - jump to:
Answers
You'll quickly run into an issue with different users (or even the same users) uploading different files with the same name I reckon. However, what you want is possible - use the
__NAME__
option - see the docs here.That's called an "orphaned file" in Editor terminology. See the docs for that here.
Allan
Thanks Allan, thanks for the quick reply and I got it to work straight away!
I am aware of the danger of similar file name but if I later want to export the PDF files (this is a reports database) the user can not see where it came from. "Project Oslo 2025.pdf" is easier to understand what is instead of "32.pdf". I have a link to see the PDF in a new window. I now have the original filename in the "files" DB so I would have to do some mapping if I want to save the files. Or am I thinking too complicated?
In case someone would like to see the complete uploads.php from the upload example for Editor:
The way to handle unique filenames, but having the file download with the original name is to store them in the file system using the primary key as the file name, and then have a single common download script (e.g.
download?id=32
) which would set the correct content type and file name headers for the download, and then have it read and echo out the file.Allan