服务器响应代码0使用upload dropzone.js获取此错误

时间:2016-10-10 08:26:24

标签: php jquery ajax dropzone.js

我的服务器端上传代码

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods:GET,POST,PUT,HEAD,DELETE,TRACE,COPY,LOCK,MKCOL,MOVE,PROPFIND,PROPPATCH,UNLOCK,REPORT,MKACTIVITY,CHECKOUT,MERGE,M-SEARCH,NOTIFY,SUBSCRIBE,UNSUBSCRIBE,PATCH');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description,X-PINGOTHER');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age', '1000');
date_default_timezone_set('Asia/Kolkata');
include_once('connection.php');

if(!empty($_FILES)){

//database configuration

$random_digit=rand(0000,9999);

$targetDir = "uploads/";
$fileName = $_FILES['file']['name'];
$new_file_name=$random_digit.$fileName;
$targetFile = $targetDir.$new_file_name;

if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
    //insert file information into db table
   // mysql_query("INSERT INTO vrecord (file_name, uploaded) VALUES('".$fileName."','".date("Y-m-d H:i:s")."')");
    mysql_query("insert into vrecord(vdate,sid,purpose,remark,nvdate,status,file,submitdate,uid,km) values(str_to_date('$vdate','%d/%m/%Y'),'$sid','$purpose','$remark',str_to_date('$nvdate','%d/%m/%Y'),'$status','$targetFile', NOW(),$uid,$km)");
}

} ?&GT;

用于上传的Dropzone代码

var myDropzone = new Dropzone("#myId", {
                url: 'https://schoolearth.net/myc/upload.php',
                autoProcessQueue:false,
                method: "post",
                withCredentials: true, // For CORS
                addRemoveLinks: true,
                maxFiles: 5,
                maxFilesize: 20,
                headers: {
                    'x-csrf-token': document.querySelectorAll('meta[name=csrf-token]')[0].getAttributeNode('content').value,
                },
                dictDefaultMessage: 'Click To Upload Image',
                init: function() {
                    console.log('init');
                    this.on("maxfilesexceeded", function (file) {
                        alert("No more files please!");
                        this.removeFile(file);
                    });
                    this.on("sending", function(file, xhr, formData) {
                        formData.append("vdate", $('#req-date').val());
                        formData.append("sid", $('#req-schoolname').val());
                        formData.append("purpose", $('#req-purpose').val());
                        formData.append("remark", $('#req-remark').val());
                        formData.append("nvdate", $('#req-nextdate').val());
                        formData.append("status", $('#req-status').val());
                        formData.append("uid", uid);
                        formData.append("km",$('#req-km').val());
                    });
                    this.on("error", function(file, response) {
                        // do stuff here.
                        alert(response);

                    });
                    this.on("success", function(file, responseText) {
                        alert(responseText);
                    });
                    this.on("addedfile", function(file) { fad=1; });
                    this.on("removedfile", function(file) { fad=0; });
                }



            });
myDropzone.processQueue();
                    myDropzone.on("complete", function (file) {
                        if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
                            var box = bootbox.alert(' <i class="ace-icon fa fa-info-circle bigger-250 green"></i><b class="green" >Visit Record Successfully Submitted..</b>');
                            box.find(".btn-primary").removeClass("btn-primary").addClass("btn-success");
                            $('#req-date').val('');
                            $('#req-schoolname').val('');
                            $('#req-purpose').val('');
                            $('#req-remark').val('');
                            $('#req-nextdate').val('');
                            $('#req-status').val('');
                            $('#req-km').val('');
                        }

                        myDropzone.removeFile(file);
                    });

当我点击上传时,错误服务器响应代码为0, 还有一件事,如果我添加一个插入查询它可以工作,但如果我上传任何文件到服务器它会给出错误。

0 个答案:

没有答案