PDA

View Full Version : Secure Uploading



SysX
08-11-2005, 08:13 AM
How can I restrict the type of file that a person uploads when I allow them to upload and edit the file to my server through an web-browser using PHP? :confused:

cr3ative
08-11-2005, 09:45 AM
$allowed_types = array(
"image/gif" => "gif",
"image/pjpeg" => "jpg",
"image/jpeg" => "jpg",
"image/jpeg" => "jpeg",
"image/bmp" => "bmp",
"image/png" => "png",
);
if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) {
echo ("Bad type.");
exit;
}
That's a code extract from my upload script at www.b3ta.cr3ation.co.uk - it's from a php which is POST'ed to. Hopefully it'll give you some ideas and allow you to adapt it to your variable names.

cr3

SysX
08-11-2005, 10:36 AM
Cheers