Checking the format of a file, and other stuff

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Clippit
Forum Newbie
Posts: 5
Joined: Mon Feb 27, 2006 2:19 pm

Checking the format of a file, and other stuff

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Clippit
Forum Newbie
Posts: 5
Joined: Mon Feb 27, 2006 2:19 pm

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Look in Code Snippets for posts by onion2k, or just in general, posts by onion2k.
Post Reply