使用dropzone上传图片时POST ajax出错

时间:2017-01-13 08:41:09

标签: javascript jquery ajax laravel dropzone.js

我有一个表单,其中包含了dropzone.js。在我收到POST错误后,插件工作到预览图像:500 (Internal Server Error)上的dropzone.js:1386

Dropzone.prototype.submitRequest = function(xhr, formData, files) {
      return xhr.send(formData);<--here
    }; 

我的观点:

Dropzone.options.images = false;
	$("#images").dropzone({ 
 	url: "{{url('/')}}/ajax-uploadvehicleimage",
 	paramName: "file",
 	maxFiles: 10,
    maxfilesexceeded: function(file) {
        this.removeFile(file);
       	alert('you no have more picture avaible! Pay for more here');
    },
     error: function(file, response) {
        if($.type(response) === "string")
            var message = response; //dropzone sends it's own error messages in string
        else
            var message = response.message;
      
        file.previewElement.classList.add("dz-error");
        _ref = file.previewElement.querySelectorAll("[data-dz-errormessage]");
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            node = _ref[_i];
            _results.push(node.textContent = message);
        }

        return _results;
    },
     success: function(file,done) {
       alert(done);
    }
});
<div id="images" class="dropzone">
	</div>

路线:

Route::post('/ajax-uploadvehicleimage','VehicleAddController@uploadimg');

控制器:

public function uploadimg(){
         if (Request::hasFile('file'))
    {
        //houston we have a file!
        $file = Request::file('file');

        //move it to our public folder and rename it to $name
        Request::file('file')->move('images', 'insert_file_name.'.$file->getClientOriginalExtension());
        echo 'file uploaded!';
        var_dump($file);
    }else{
        echo 'no file, no bueno';
    }
    }

可以解释我的问题是什么,我该如何改变或采样?我读了很多关于这个的话题,但没有人被释放!

编辑: Laravel.log:

[2017-01-13 07:55:38] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Can't use function return value in write context' in E:\bitnami\apache2\htdocs\vehicle\app\Http\Controllers\VehicleAddController.php:103
Stack trace:
#0 {main}  

1 个答案:

答案 0 :(得分:1)

尝试将其更改为此

public function uploadimg(){
            $file = Request::file('file');
      if ($file) {
            //move it to our public folder and rename it to $name
            $file->move('images', 'insert_file_name.'.$file->getClientOriginalExtension());
            echo 'file uploaded!';
            var_dump($file);
        }else{
            echo 'no file, no bueno';
        }
     }

当您在上传时转到chrome上的网络标签页时,错误的响应预览会是什么?