Jump to content

Recommended Posts

Hello List!

 

I'm working on some file uploading code, and need to check the file type and then verify that it's either ".doc, .txt, .pdf, or .xls" -- if it's not one of those, display an error and not upload it.  But, I'm not sure how to do this; I think I want to implement $_FILES[my_file_name]["type"] somehow, but I just don't know where to begin or how to implement it???

 

Would someone out there be able to help me get over this hump that I've been stuck on?

 

Here's my file upload code:

 

elseif (preg_match("/upload/i", $submit))  // $submit == "Save";
{

    if ($_FILES["glossary_file"]["tmp_name"] )
    {
       if ( move_uploaded_file($_FILES["glossary_file"]["tmp_name"], $uploadpath.$_FILES["glossary_file"]["name"]) )
       {
    $error_msg = "Successfully Uploaded Glossary File";

}
else
{
    $error_msg = "Error Uploading Glossary File";
        }
    }
    else
   {
$error_msg = "Error Uploading Glossary File";	   	
    }
}

 

Thanks in advance for your help and expertise!

-j.g.

Link to comment
https://forums.phpfreaks.com/topic/65489-how-to-checkverify-file-types/
Share on other sites

Never, ever, under any circumstances use the type field provided in the $_FILES array; it is set by the browser and not PHP or the web server.  This means the value can be easily faked.

 

Refer to this:

http://www.php.net/manual/en/ref.fileinfo.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.