views:

334

answers:

6

What would you say are the essential steps in verifying a file upload?

I'd tend to check the MIME type, give it a new (random) name, make sure its got an allowed file extension, and then I'd check the contents of the file. How do you go about it?

+1  A: 

What does it mean that the file is "safe"? That it doesn't contain a virus? That you have enough memory to load it?

Also, please add clarifications by editing your original question, not by posting an answer.

Steve
A: 

Check the file type, check the file size, the image dimension.

These are the 3 I always check to be sure to have good result.

Daok
A: 

If you are receiving a gif file for a profile photo as example, you should check that the mime type is gif.
And that way you avoid uploading bad files.
Here you have an example using php.

Gero
A: 

To make sure it's safe, is what I mean by verifying it.

What does "safe" mean? Virus free? Unless you plan to execute it, you don't need to check for viruses.
S.Lott
A: 

Depends on the expected file contents... might be a good idea to run a virus scan on the file.

EmmEff
+1  A: 

Check (in this order): the file MIME type (and note certain browsers have MIME type detection problems...); that the file path exists; that a previous version of the file with the same name doesn't exist, else, rev it; that the file isn't too big; on success, run a virus check on the server.

Ash Machine