Page 1 of 1

Checking the format of a file, and other stuff

Posted: Mon Feb 27, 2006 4:47 pm
by Clippit
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.

Posted: Mon Feb 27, 2006 4:54 pm
by feyd
getimagesize() returns the type information, width and height. filesize() will tell you the size in bytes. Divide that by 1024 and you get in kilobytes.

Posted: Mon Feb 27, 2006 4:59 pm
by Clippit
How cool, my thanks!

Now if I only could find one easy to use, and free, PHP thumbnail generator to get this thing rolling...

Posted: Mon Feb 27, 2006 5:12 pm
by feyd
Look in Code Snippets for posts by onion2k, or just in general, posts by onion2k.