Checking the format of a file, and other stuff
Posted: Mon Feb 27, 2006 4:47 pm
Hello.
I allow my users to upload an image to my server. This works, cool. But it is within the human nature to abuse things, and this is why I must include some way of checking a few things before the file is accepted on the server's directory, and not shot down on sight (removed).
The file must be a JPG (JPEG) image, that is no bigger than 30kB and it can't be more than 400 pixels wide nor more than 400 pixels tall.
I can do the math myself, but reading such stuff from the image is where I need help.
To put it short, I need to read the file's actual type (the file extension could lie), size in kiloBytes, width and height.
Now the system could allow any registered user to upload a filthy movie or anything to my server, even a file with a virus! That's just horrible...
Thank you all.
I allow my users to upload an image to my server. This works, cool. But it is within the human nature to abuse things, and this is why I must include some way of checking a few things before the file is accepted on the server's directory, and not shot down on sight (removed).
The file must be a JPG (JPEG) image, that is no bigger than 30kB and it can't be more than 400 pixels wide nor more than 400 pixels tall.
I can do the math myself, but reading such stuff from the image is where I need help.
To put it short, I need to read the file's actual type (the file extension could lie), size in kiloBytes, width and height.
Now the system could allow any registered user to upload a filthy movie or anything to my server, even a file with a virus! That's just horrible...
Thank you all.