Hearaman
Hearaman

Reputation: 8726

Unable to upload doc and docx files

Here i am trying to upload pdf, doc and docx files. Pdf files are uploading well but doc and docx files are not uploading. I kept enctype="multipart/form-data" property in form tag. What's the wrong with my code.

if ((($_FILES["uploadjob"]["type"] == "application/pdf") 
    || ($_FILES["uploadjob"]["type"] == "application/doc") 
    || ($_FILES["uploadjob"]["type"] == "application/docx"))) {
    if ($_FILES["uploadjob"]["error"] > 0) {
        echo "Return Code: ".$_FILES["uploadjob"]["error"]."<br />";
    } else {
        move_uploaded_file($_FILES["uploadjob"]["tmp_name"], "jobuploads/".$_FILES["uploadjob"]["name"]);
        // echo $_FILES["file"]["tmp_name"];
        $filename = $_FILES["uploadjob"]["name"];
    }
} else {
    echo "<br><br><br><center><font size='3' color='red'>Invalid file. Please upload only pdf, doc or docx files.</font><br><br> This page will be redirected after 5 seconds, Please wait................</center>";
    echo "<meta HTTP-EQUIV='REFRESH' content='5; url=jobopening.php'>";
    exit;
}

Upvotes: 2

Views: 4816

Answers (1)

Chris G.
Chris G.

Reputation: 3981

Check the Mime type of the document you are uploading, the rest of your code looks correct. You can check this with $_FILES[]["type"]. If the Mime type is different, add it to your IF condition and see if it works then.

If it still doesn't work, check that the filesize is under the limit set in PHP.ini. You can find filesize limits with phpinfo();

Upvotes: 3

Related Questions