note 77697 added to features.file-upload

From: Date: Sun, 09 Sep 2007 10:51:18 +0000
Subject: note 77697 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-130325@lists.php.net to get a copy of this message
I have always wanted to just allow image files; and found using an array which would work on IE, FF, And Opera etc. would be to define the "image/name" for all of those. as IE is "image/x-name" and FF is "image/name" etc. <?php function image_valid($type) { $file_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/jpeg' => 'jpeg', 'image/gif' => 'gif', 'image/X-PNG' => 'png', 'image/PNG' => 'png', 'image/png' => 'png', 'image/x-png' => 'png', 'image/JPG' => 'jpg', 'image/GIF' => 'gif', 'image/bmp' => 'bmp', 'image/bmp' => 'BMP', ); if(!array_key_exists($type, $file_types)) { return "FALSE"; } else { return "TRUE"; } } if(image_valid($_FILES['user_file']['type']) === "FALSE") { die("Image file is not valid"); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 172.142.93.173 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- https://master.php.net/note/edit/77697 Del: integrated -- https://master.php.net/note/delete/77697/integrated Del: useless -- https://master.php.net/note/delete/77697/useless Del: bad code -- https://master.php.net/note/delete/77697/bad+code Del: spam -- https://master.php.net/note/delete/77697/spam Del: non-english -- https://master.php.net/note/delete/77697/non-english Del: in docs -- https://master.php.net/note/delete/77697/in+docs Del: other reasons-- https://master.php.net/note/delete/77697 Reject -- https://master.php.net/note/reject/77697 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130325) next »