note 87594 added to features.file-upload
| From: | RobertW dot at osu1 dot php dot net | Date: | Fri, 12 Dec 2008 03:05:18 +0000 |
| Subject: | note 87594 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148055@lists.php.net to get a copy of this message | ||
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
----
Server IP: 209.41.74.194
Probable Submitter: 70.178.6.249
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- https://master.php.net/note/edit/87594
Del: integrated -- https://master.php.net/note/delete/87594/integrated
Del: useless -- https://master.php.net/note/delete/87594/useless
Del: bad code -- https://master.php.net/note/delete/87594/bad+code
Del: spam -- https://master.php.net/note/delete/87594/spam
Del: non-english -- https://master.php.net/note/delete/87594/non-english
Del: in docs -- https://master.php.net/note/delete/87594/in+docs
Del: other reasons-- https://master.php.net/note/delete/87594
Reject -- https://master.php.net/note/reject/87594
Search -- https://master.php.net/manage/user-notes.php