406表单提交1不可接受的错误

时间:2014-03-30 15:07:46

标签: php http-status-code-406

我在php文件中得到406不可接受的错误。我使用jQuery提交。

这是我在

上获得406错误的代码
<?php

include('../db.php');



$UploadDirectory    = '../uploaded_images/';


if (!@file_exists($UploadDirectory)) {

    //destination folder does not exist

    die("Make sure Upload directory exist!");

}



if($_POST)

{       

        if(!isset($_POST['category']) || strlen($_POST['category'])<1)

    {

        //required variables are empty

        die('<div class="errormsgbox">Please select a category.</div>');

    }



    if(!isset($_POST['mName']) || strlen($_POST['mName'])<1)

    {

        //required variables are empty

        die('<div class="errormsgbox">Please add a title.</div>');

    }



    if(!isset($_POST['aff']) || strlen($_POST['aff'])<1)

    {

        //required variables are empty

        die('<div class="errormsgbox">Please add your affiliate URL.</div>');

    }



    if(!isset($_POST['disc']) || strlen($_POST['disc'])<1)

    {

        //required variables are empty

        die('<div class="errormsgbox">Please add a small description.</div>');

    }





    if(!isset($_FILES['mFile']))

    {

        //required variables are empty

        die('<div class="errormsgbox">Please add a image</div>');

    }



    if(!isset($_POST['price']) || strlen($_POST['price'])<1)

    {

        //required variables are empty

        die('<div class="errormsgbox">Please add price.</div>');

    }



    if($_FILES['mFile']['error'])

    {

        //File upload error encountered

        die(upload_errors($_FILES['mFile']['error']));

    }



    $FileName           = strtolower($_FILES['mFile']['name']); //uploaded file name

    $ImageExt           = substr($FileName, strrpos($FileName, '.')); //file extension

    $Active             = 1;//File active

    $FileType           = $_FILES['mFile']['type']; //file type

    $FileSize           = $_FILES['mFile']["size"]; //file size

    $RandNumber         = rand(0, 9999999999); //Random number to make each filename unique.

    $Date               = date("F j, Y");



    $FileTitle          = $mysqli->escape_string($_POST['mName']); // file title

    $Category           = $mysqli->escape_string($_POST['category']); // category 

    $AffURL             = $mysqli->escape_string($_POST['aff']); // afflite url

    $Description        = $mysqli->escape_string($_POST['disc']); // description

    $Price              = $mysqli->escape_string($_POST['price']); // price





        switch(strtolower($FileType))

    {

        //allowed file types

        case 'image/png': //png file

        case 'image/gif': //gif file 

        case 'image/jpeg': //jpeg file

        case 'image/bmp': //bmp file

            break;

        default:

            die('Unsupported Image File!'); //output error

    }





    //Image File Title will be used as new File name

    $NewFileName = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), strtolower($FileTitle));

    $NewFileName = $NewFileName.'_'.$RandNumber.$ImageExt;



 //Rename and save uploded image file to destination folder.

   if(move_uploaded_file($_FILES['mFile']["tmp_name"], $UploadDirectory . $NewFileName ))

   {





// Insert info into database table.. do w.e!

        $mysqli->query("INSERT INTO listings(title, aff_url, discription, price, image, catid, date, active) VALUES ('$FileTitle', '$AffURL','$Description','$Price','$NewFileName','$Category','$Date','$Active')");



        die('<div class="infomsgbox">New listing added successfully.</div>');





   }else{

        die('<div class="errormsgbox">There seems to be a problem. please try again.</div>');

   } 

}



function upload_errors($err_code) {

    switch ($err_code) { 

        case UPLOAD_ERR_INI_SIZE: 

            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 

        case UPLOAD_ERR_FORM_SIZE: 

            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 

        case UPLOAD_ERR_PARTIAL: 

            return 'The uploaded file was only partially uploaded'; 

        case UPLOAD_ERR_NO_FILE: 

            return 'No file was uploaded'; 

        case UPLOAD_ERR_NO_TMP_DIR: 

            return 'Missing a temporary folder'; 

        case UPLOAD_ERR_CANT_WRITE: 

            return 'Failed to write file to disk'; 

        case UPLOAD_ERR_EXTENSION: 

            return 'File upload stopped by extension'; 

        default: 

            return 'Unknown upload error'; 

    } 

} 

?>

有人能指出我哪里出错了。这在localhost中工作正常。

我真的很适合你这方面的帮助。

0 个答案:

没有答案