File upload is one of the features that most often turns into a vulnerability in a web application. Profile photos, documents, invoices, attachments: each one is untrusted input coming from a user and stored on your server. In the projects we review, the problem rarely comes from a sophisticated attack; it usually comes from three simple gaps: a wrongly validated type, an unchecked size, and a file saved in the wrong place.
Type validation: don't trust the extension or the client
The $_FILES['dosya']['type'] value is information sent by the browser, and an attacker can change it freely. An extension check alone isn't enough either; names like shell.php.jpg, or double extensions that get executed depending on the server configuration, cause trouble. What you can trust is the file's content:
- Read the real MIME type on the server side with
finfo_open(FILEINFO_MIME_TYPE). - Keep the allowed types in an allowlist; don't build "everything except these" logic.
- If you're accepting images, reprocess and save the image with
getimagesize()or GD; this cleans out both corrupted content and embedded code. - In Laravel, the
mimetypesandmimesvalidation rules look at the content; still, define the allowlist yourself.
Size limits: in three places at once
A size limit set only in application code falls short. In PHP, the upload_max_filesize and post_max_size settings come into play, and on the web server, Nginx's client_max_body_size value. If these values don't line up, the user sees a meaningless error, or a large request makes it all the way to the server and consumes resources. First set a reasonable upper limit at the server level, then validate each form's own limit in the application and give the user a clear message.

During the upload, also check the $_FILES['dosya']['error'] value. Any code other than UPLOAD_ERR_OK is a problem; code that ignores these and carries on can end up saving partially uploaded files.
Storage mistakes
The most dangerous mistake is storing the uploaded file under the web root with its original name. Here's the layout we recommend:
- Don't take the file name from the user; generate a random, unique name, and keep the original name in the database if you need it.
- Derive the extension from the validated MIME type, not from the name the user supplied.
- Keep files that don't need to be public outside the web root, under
storage/appin Laravel, and serve them through a controlled endpoint. - Disable script execution in the upload directory through the server configuration.
- Use
move_uploaded_file(); moving files withrename()orcopy()skips the upload validation.
Think about the download side too
Even if the upload is secure, mistakes can happen when the file is served. When serving the file, set the Content-Type header from the validated type, prefer Content-Disposition: attachment for user content, and add the X-Content-Type-Options: nosniff header. If you're building the file path from a request parameter, guard against ../ directory traversal attempts by resolving the path with realpath() and verifying that it stays inside the expected directory. Don't forget the authorization check either: a user should only be able to access their own files, never reach someone else's through guessable IDs.
Large files and virus scanning
For large file uploads, chunked uploads or uploading directly to object storage via a signed URL free up PHP processes. In systems where documents from users will be distributed to others, running a scanner like ClamAV as a queued job is a sensible extra layer. Mark files that haven't passed the scan as "pending" and don't serve them until they pass.
When you write a new upload field, ask yourself these questions: Am I validating the file's type from its content? Is the size limit consistent on the server and in the application? Am I the one generating the file name? Is the file outside the web root, and is it served only to authorized users? If you can't give a clear yes to all four, that upload field isn't ready yet. This list is useful in code review as well, because instead of hunting for vulnerabilities one by one, it's enough to find the missing answer.

If you'd like to review the security of the upload flows in your application, or build a new document management module on solid ground from the start, write to us through our contact page. More often than not, we can close these kinds of vulnerabilities without writing a new feature, with just a few lines of the right checks.