【问题标题】:Error with POST ajax during image upload with dropzone使用 dropzone 上传图像时 POST ajax 出错
【发布时间】:2017-05-28 13:55:39
【问题描述】:

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

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}  

【问题讨论】:

  • 你的 Laravel 日志文件里写了什么?那里应该有一个堆栈跟踪。如果没有,请开启 App debug。
  • @Erin 添加了日志
  • 只是出于兴趣,您运行的是什么版本的 php?
  • @rchatburn 5.6.21 (cli)

标签: javascript jquery ajax laravel dropzone.js


【解决方案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 上的网络选项卡时,错误的响应预览是什么?

【讨论】:

  • 同样的问题!是的,当我选择时,它来了预览,预览完成,问题来了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-20
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-13
  • 2017-08-07
相关资源
最近更新 更多