Jump to content

posting pictures


astralaaron

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...