【问题标题】:Dropzone.js - Laravel | 500 Internal Server ErrorDropzone.js - Laravel | 500内部服务器错误
【发布时间】:2018-08-01 08:17:42
【问题描述】:

我想用 dropzone.js 上传我的图片,我在服务器端获取图片,没关系。但是当我想尝试保存时,它会给出500 internal server error

Dropzone.options.mDropzoneTwo = {
  paramName: "file", // The name that will be used to transfer the file
  maxFiles: 10,
  maxFilesize: 10, // MB
  url: 'images/save' ,
  method: 'POST',
  headers: {
    "X-CSRF-TOKEN": document.head.querySelector("[name=csrf-token]").content
   },
  uploadMultiple: true,
  accept: function(file, done) {
          done();
          },
  success: function () {
          console.log()
          }
        };

这是我的控制器。我正在将图像保存到 public/uploads 文件夹。

 $realname = str_slug(pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME));
 $extension = $request->file('file')->getClientOriginalExtension();
 $new_name = $realname."-".time().".".$extension;
 $request->file('file')->move(public_path('uploads/'.str_slug($new_name)));
 $image = new Media();
 $image->image = str_slug($new_name);
 $image->image_path = "images/".str_slug($new_name);
 $image->image_alt_name = $realname;
 $image->save();

【问题讨论】:

  • 来自服务器的 500 响应表明您的 Laravel 控制器方法正在引发某种错误。我会检查你的日志文件/storage/logs/laravel.log,看看你是否在那里找到任何东西。
  • 它说 = local.ERROR: 在数组 {"userId":1,"email":"cervantes.ias@gmail.com","exception" 上调用成员函数 getClientOriginalName(): "[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): 在 /var/www/parti/app/Http/Controllers/MediaController 的数组上调用成员函数 getClientOriginalName()。 php:17)
  • 这意味着什么?没看懂

标签: javascript laravel laravel-5 xmlhttprequest dropzone.js


【解决方案1】:

根据 cmets --

这意味着您的应用程序没有在$request->file('file') 上获取文件对象,您可以通过打印$request 获取更多信息,然后您可以检查文件是否从客户端脚本发送出去

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-25
    • 2015-08-12
    • 1970-01-01
    • 2017-04-12
    • 2020-10-01
    • 2019-01-08
    • 2016-05-14
    • 2016-02-12
    相关资源
    最近更新 更多