Jump to content

posting pictures


astralaaron
 Share

Recommended Posts

Hey I have options on a website for the admin to post pictures. since it was just the admin posting the pictures i did not think to worry about what kind of file was being uploaded.now they want the members to also be able to post pictures.. and i thought ok no problem... but then i realized what if some person uploaded a huge file, or some other file type...can someone tell me how to check if the file is right? jpg, gif or whatever common image types please help, thanks!

Link to comment
Share on other sites

The best way is to just have a list of allowed extensions and to check the extension. You can get the extension of a filename like this:$ext = array_pop(explode(".", $fname));You can compare that with an array of allowed extensions to see if it's valid or not.

$allowed = array('jpg', 'gif', 'png');if (in_array($ext, $allowed))  echo "ok";else  echo "not ok";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...