Page 1 of 1

MiME upload help

Posted: Thu Sep 18, 2008 4:07 am
by Addos
Hi,
I need to be able to allow a Word document and a pdf only to be uploaded and was trying to use the code below. However this is simply not uploading at all. This is what I was using.

Code: Select all

<?PHP 
    $FILE_MIMES = array('application/msword','application/pdf'); 
 
if (isset($_FILES['fupload'])){
if ($_FILES['fupload']['type'] == '$FILE_MIMES' ) { // etc ?>
If I simply use this

Code: Select all

<?PHP 
    
if (isset($_FILES['fupload'])){
if ($_FILES['fupload']['type'] == 'application/msword' ) { // etc ?>
….then this will allow me to upload a Word doc or PDF (if I change 'application/msword' msword' to 'application/pdf using them individually’) but I can’t get the script to run with both together using an array.

Any ideas?
Thanks

Re: MiME upload help

Posted: Thu Sep 18, 2008 10:14 am
by rbc
Try something like this:

Code: Select all

// Check for a file.
if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) {
 
// Validate file type.
$allowed = array ('image/gif', 'image/jpeg', 'image/jpg', 'etc');
                        
if (in_array($_FILES[$filename]['type'], $allowed)) {
 
     // Then upload file.