I have no idea how to store uploaded files on my server. For example, should I always rename the uploaded file to a random string like 458783576487365934 and always store the files in the same folder? For example if I store pdf documents or images, do I put all the pdfs in the same folder (but with a random name so I can upload documents with same name)? If I do so, I would like that when the user goes to the url
/files/458783576487365934 for instance, the downloaded file has its original name and not the real stored name but how?
I can store in DB the path and the original name but how to tell the browser its real name when we go to
(I don't care about the actual process of uploading, I know about $_FILES and I use Symfony anyway)
- You should store original name in the database.
- You should not store files with original name, it's insecure. Use server-generated names.
- You can tell browser the name of file to download by the HTTP headers (
header('Content-Disposition: inline; filename="original name.pdf"');
- You should store files in different directories when you are going to save millions of files. Each new file in the directory decreases the performance of I\O operations.