Php Krajee文件输入无效的json响应

Php Krajee文件输入无效的json响应,php,jquery,ajax,json,file-upload,Php,Jquery,Ajax,Json,File Upload,我试图将krajee文件输入集成到我现有的表单中 当我从我的计算机浏览一个文件并单击upload按钮(插件内置)时,我得到了以下错误:SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符 这个插件的作者告诉我,我必须在我的php文件中编写有效的json响应,这样才能工作,但他没有时间帮助像我这样的个案。所以我阅读了网站上的文档,它有以下部分:(你可以在上面的演示网站上找到) 发送数据(从服务器) uploadUrl中设置的服务器方法必须将数据作为json编码的对象发送

我试图将krajee文件输入集成到我现有的表单中

当我从我的计算机浏览一个文件并单击upload按钮(插件内置)时,我得到了以下错误:SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符

这个插件的作者告诉我,我必须在我的php文件中编写有效的json响应,这样才能工作,但他没有时间帮助像我这样的个案。所以我阅读了网站上的文档,它有以下部分:(你可以在上面的演示网站上找到)

发送数据(从服务器)

uploadUrl中设置的服务器方法必须将数据作为json编码的对象发送回。您必须发送的唯一关键是错误,这将是上传的错误消息,并将帮助插件识别文件上传中的错误。例如,来自服务器的响应将作为{错误:'不允许您上载这样的文件。'}发送。注意:插件将自动验证并显示ajax异常错误

重要的

您必须从服务器发送有效的JSON响应,否则上载过程将失败。即使没有遇到任何错误,也必须至少从服务器发送一个空的JSON对象{}

要捕获并显示验证错误,JSON响应数据必须包含错误键,其值将是要显示的错误HTML标记。这是如上所述的设置

不幸的是,我不能理解它,因为我只是一个新的php学习者,这超出了我的范围。但是我这里有我的php文件,希望一些专家能帮助我添加json响应,正如上面的文档所解释的那样。提前非常感谢

这是我的php文件:

<?php
if(isset($_POST["submit"])){
require("../configs/dbconnect.php");
/*Form variable   */
$owner = mysql_real_escape_string($_POST["owner"]);
$title = mysql_real_escape_string($_POST["title"]);
$description = mysql_real_escape_string($_POST["description"]);
$city = mysql_real_escape_string($_POST["city"]);
$brand = mysql_real_escape_string($_POST["brand"]);
$marketprice = mysql_real_escape_string($_POST["marketprice"]);
$price = mysql_real_escape_string($_POST["price"]);
$phone = mysql_real_escape_string($_POST["phone"]);
/*** the upload directory ***/
$upload_dir= 'uploads';

/*** numver of files to upload ***/
$num_uploads = 5;

/*** maximum filesize allowed in bytes ***/
$max_file_size  = 5000000;

/*** the maximum filesize from php.ini ***/
$ini_max = str_replace('M', '', ini_get('upload_max_filesize'));
$upload_max = $ini_max * 1024;

/*** a message for users ***/
$msg = 'Please select files for uploading';

/*** an array to hold messages ***/
$messages = array();
$err=array();

/*** check if a file has been submitted ***/
if(isset($_FILES['file']['tmp_name']))
{
    /** loop through the array of files ***/
    for($i=0; $i < count($_FILES['file']['tmp_name']);$i++)
    {
        // check if there is a file in the array
        if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))
        {
            $messages[] = 'No file uploaded';
        }
        /*** check if the file is less then the max php.ini size ***/
        //elseif($_FILES['image']['size'][$i] > $upload_max)
        //{
        //    $messages[] = "File size exceeds $upload_max php.ini limit";
        //}
        // check the file is less than the maximum file size
        elseif($_FILES['file']['size'][$i] > $max_file_size)
        {
            $messages[] = "File size exceeds $max_file_size limit";
        }
        else
        {
            //$temp = explode(".", $_FILES["file"]["name"][$i]);
            //$extension = end($temp);
            //$name[$i] = sha1(microtime()) . "." . $extension;
            $name[$i]=$_FILES["file"]["name"][$i];
            // copy the file to the specified dir 
            if(move_uploaded_file($_FILES['file']['tmp_name'][$i],$upload_dir.'/'.$name[$i]))
            {
                /*** give praise and thanks to the php gods ***/
                $messages[] = $name[$i].' uploaded';
                $image_path[$i]=$upload_dir.'/'.$name[$i];
            }
            else
            {
                /*** an error message ***/
                $messages[] = 'Uploading '.$name[$i].' Failed';
            }
        }
    }
}
$image_path_string=serialize($image_path);
$sql = "INSERT INTO memberpost(owner, title, description, city, brand, marketprice, price, phone, image) VALUES ('$owner', '$title','$description','$city','$brand','$marketprice','$price','$phone', '" . $image_path_string . "')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
 if(sizeof($messages) != 0)
{
    foreach($messages as $err)
    {
        echo $err.'<br />';
    }
}
}
?>

你的
回声
我想。。。 将错误放在任何变量上,然后
echo json\u encode(变量名)
。这就是如何发送JSON对象。

请使用新代码。它们不再得到维护,而是在使用。而是学习,并使用或。