note 27380 deleted from features.file-upload by vincent
| From: | vincent@php.net | Date: | Thu, 11 Sep 2003 12:17:00 +0000 |
| Subject: | note 27380 deleted from features.file-upload by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56103@lists.php.net to get a copy of this message | ||
Note Submitter: alex@sara-and-david.com
----
Here's a quick, simple, and easily modified way to determine file type of the uploaded file. (I
used images for my example.)
$imgarray = array("image/pjpeg", "image/jpeg", "image/gif",
"image/png", "image/x-png");
$filetype = $_FILES['userfile']['type'];
$filename = $_FILES['userfile']['name'];
$filesize = $_FILES['userfile']['size'];
if (!$filesize){
echo "The file you specified is either an invalid name, or contains Zero bytes.";
}elseif (!in_array($filetype,$imgarray)){
echo 'Invalid filetype. Please use only a .JPG, .GIF, or .PNG file.';
}else{
echo 'You\'ve uploaded a file named '.$filename.'!';
}