Cake php上传docx文件返回net :: ERR_EMPTY_RESPONSE

时间:2016-11-06 14:04:22

标签: php apache cakephp

我正在尝试调试为什么docx和doc总是返回net :: ERR_EMPTY_RESPONSE,我也检查Cake php错误日志但是错误日志显示为空白,我很难解决这个问题,而pdf和xlsx是工作文件,请试着帮助我。下面是我的代码

public function postDocumentForm() {
        //die('Rashid');
        $this->layout = 'Admin.ajax';
        $this->autoRender = false;
        $result = 'error';
        $message = '';
        $errors = '';

        if(!$this->request->is('ajax')) {
            exit(0);
        }

        if($this->request->is('post')) {
            //pr($this->request->data); die;
            $client_id = isset($this->request->data['Document']['client_id'])?$this->request->data['Document']['client_id']:null;
            $category_id = isset($this->request->data['Document']['category_id'])?$this->request->data['Document']['category_id']:null;
            if(!empty($client_id) && !empty($category_id)) {
                $this->Document->create();
                $this->Document->set($this->request->data);
                $this->Document->setValidation('upload_client_document');

                if($this->Document->validates() === true) {
                    $res = $this->_uploadFile($this->request->data['Document']['document']);                
                    if($res !== false) {
                        $data['Document'] = array(
                            'category_id' => $category_id,
                            'description' => $this->request->data['Document']['description'],
                            'document' => $res['file_name'],
                            'file_path' => $res['file_path'],
                            'size' => $res['size'],
                            'type' => $res['type'],
                            'comment' => $this->request->data['Document']['comment'],
                            'is_required_signature' => isset($this->request->data['Document']['is_required_signature'])?$this->request->data['Document']['is_required_signature']:0,
                            'access' => $this->request->data['Document']['access'],
                            'uploaded_by' => $this->user_id
                        );

                        $data['ClientDocument'] = array('client_id'=>$client_id);

                        $this->Document->bindModel(
                            array(
                                'hasOne'=>array(
                                    'ClientDocument' => array(
                                        'className' => 'ClientDocument',
                                        'foreignKey' => 'document_id'
                                    )
                                )
                            )
                        );

                        if($this->Document->saveAll($data, array('validate'=>false))) {
                            if(isset($this->request->data['Document']['is_required_signature'])) {
                                    $docid=$this->Document->id;
                                    $this->hellosign($client_id,$docid);
                            }
                            $message = 'Document has been uploaded.';
                            $result = 'success';
                        } else {
                            $message = 'Document could not be uploaded please try again.';
                            $result = 'error';
                        }
                    } else {
                        $message = 'Document could not be uploaded please try again.';
                        $result = 'error';
                    }
                } else {
                    $errors = $this->_validationHtmlErrors($this->Document->validationErrors);
                    $result = 'error';
                    $message = 'Please correct document validation errors.';
                }
            } else {
                $message = 'Invalid action.';
                $result = 'error';
            }
        } else {
            $message = 'Invalid action.';
            $result = 'error';
        }

        echo json_encode(array('result'=>$result, 'message'=>$this->_getMessage($message), 'errors'=>$errors));
    }

$(document).on('submit', '#upload_client_document_form', function() {
    var client_id = $('#doc_client_id').val();
    var thisObj = $(this);
    var formData = new FormData($(this)[0]);
    var errorObj = $(this).parent().siblings('.client_document_upload_response');

    /* Loader */
    var document_upload_btn = $(this).find('#document_upload_btn');
    var document_upload_btn_loading = $(this).find('#document_upload_btn_loading');
    document_upload_btn.removeClass('active');
    document_upload_btn.attr('disabled', true);
    //document_upload_btn_loading.show();


    console.log(BASE_URL+'documents/postDocumentForm');
    var uploadedDocDivObj = thisObj.parents().eq(4).find('.cat_accord_upload_doc_div');

    $.ajax({
        url: BASE_URL+'documents/postDocumentForm',
        type: 'POST',
        data: formData,
        beforeSend: function(data) {
            console.log(data);
            errorObj.removeClass('alert-error');
            errorObj.removeClass('alert-success');
            errorObj.hide();
            $('#myloader').show();
        },
        success: function (data) {
            console.log(data);
            data = $.parseJSON(data);
            var res_data = data.message;
            //alert(data.errors);

            document_upload_btn.addClass('active');
            document_upload_btn.attr('disabled', false);
            //document_upload_btn_loading.hide();

            if (data.result == 'error') {
                if (data.errors != '') {
                    res_data += data.errors;
                }
                errorObj.addClass('alert-error');
                errorObj.html(res_data);
                errorObj.show();    
            } else {
                errorObj.addClass('alert-success');
                errorObj.html(res_data);
                errorObj.show();
                thisObj[0].reset();

                /* ajax for list uploaded documents start */
                $.ajax({
                    url: BASE_URL+'documents/getUploadedDocuments/'+client_id+'/'+category_id,
                    data: '',
                    type: 'POST',
                    beforeSend: function(data){
                        uploadedDocDivObj.html(loadingImage);
                    },
                    success: function(data) {
                        uploadedDocDivObj.html(data);
                    }
                });
                /* ajax end */
            }
            $('#myloader').hide();
            errorObj.delay(2000).fadeOut('fast');
        },
        cache: false,
        contentType: false,
        processData: false
    });
    return false;
});

1 个答案:

答案 0 :(得分:0)

我实际上在前一段时间遇到过这个问题,请查看你的查询中是否有过大的回报,有时浏览器会在返回的数组很大时停止,在这种情况下使用" recursive' =>查询为-1。