Never trust the upload
A safe upload treats everything about the file as hostile:
Tip: Generate a random server-side filename (never use the client's), strip any path, and store uploads outside the web root or somewhere the server will never execute them. Validate the real content type (not the extension or the
Content-Typeheader), cap the size, and serve downloads withContent-Disposition: attachmentand a safe content type.