note 87594 deleted from features.file-upload by googleguy
| From: | googleguy@php.net | Date: | Wed, 22 Aug 2012 01:50:44 +0000 |
| Subject: | note 87594 deleted from features.file-upload by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190167@lists.php.net to get a copy of this message | ||
Note Submitter: Robert W.
----
Here's a really fast way to get a files' extension:
<?php
$file = $_FILES['userfile'];
$allowedExtensions = array("txt", "rtf", "doc");
function isAllowedExtension($fileName) {
global $allowedExtensions;
return in_array(end(explode(".", $fileName)), $allowedExtensions);
}
if($file['error'] == UPLOAD_ERR_OK) {
if(isAllowedExtension($file['name'])) {
# Do uploading here
} else {
echo "Invalid file type";
}
} else die("Cannot upload");
?>
This works in PHP v5+ -- haven't tested in PHP v4