PHP makes uploaded files available via the $_FILES superglobal. Safe file upload handling requires validating type, size, and name before moving the file to its destination.
Check $_FILES['file']['error'] first — never proceed if it's not UPLOAD_ERR_OK.
Validate MIME type using finfo, not the browser-supplied type.
Generate a new filename; never trust the user-supplied name.
Tip: Store uploaded files outside the web root (e.g., /var/uploads/) and serve them through a PHP script that sets the correct Content-Type header. This prevents users from uploading PHP files and executing them via the browser.