note 27380 added to features.file-upload
| From: | alex at sara-and-david dot com | Date: | Tue, 03 Dec 2002 23:25:37 +0000 |
| Subject: | note 27380 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40316@lists.php.net to get a copy of this message | ||
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.'!';
}
--
http://www.php.net/manual/en/features.file-upload.php
http://master.php.net/manage/user-notes.php?action=edit+27380
http://master.php.net/manage/user-notes.php?action=delete+27380
http://master.php.net/manage/user-notes.php?action=reject+27380