Hello!
I have a small issue with file uploads. It's not that it doesn't work, I'm just not sure if what I'm doing is bad practice or not. I'm also under the impression that just checking for the mimetype is a very thin layer of security since it can easily be faked.
Anyways, when a user submits a file to the server, it is validated by the validator (mimetype, max filesize, that kind of stuff)
Then I check the file extension just to make sure that the folder don't get bloated with image files that has a random extension. I should probably extend the validator class and add my own rule for this, though.
Then I move & rename the file using the Storage facade, since I'll be switching to Amazon S3 later.
The name is generated like this btw, if you wonder: md5(time())
I also store the filename in a table, along with other things such as a title(this is also submitted by the user ofc) and the original filename, mimetype etc.
To access the file I have a subdomain that points to storage/content, rather than the public folder.
So, for instance, you visit static.mydomain.io/filename.jpg to see the file. Directory listing is disabled and I tried to make a .htaccess that only allows you to access files with the extensions: .jpg, .jpeg, .gif, .png, .webm and .mp4 but with no luck. I don't know if it gets ignored because there's a .htaccess in the root directory or if there can only be one or if I just suck at .htaccess.
order allow,deny
<Files ~ "\.(jpg|jpeg|png|gif|webm|mp4|shtml)$">
allow from all
</Files>
I put shtml there because a 404.shtml gets generated by the webserver in that directory but it doesn't matter because the config doesn't work for me.
Any tips for an aspiring web developer when it comes to managing file uploads? Do/Dont/Absolutely dont?