javascript - Dropzone.js-Laravel | 500内部服务器错误

标签 javascript laravel laravel-5 xmlhttprequest dropzone.js

我想用 dropzone.js 上传我的图片,我在服务器端获取图片,没问题。但是当我想尝试保存时,它给出了 500 内部服务器错误

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()
          }
        };

这是我的 Controller 。我正在将图像保存到 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();

最佳答案

根据评论——

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

关于javascript - Dropzone.js-Laravel | 500内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48911187/

相关文章:

php - 如何在使用nginx的centos服务器中清除laravel应用程序的缓存

laravel - 使用Laravel计算页面浏览量

php - Laravel如何获取两个结果值的平均值

javascript - 状态未在 react 中更新

Laravel Homestead Windows 7 上共享文件夹的主机路径丢失错误

javascript - 需要 : nested require calls

php - 将数据从 foreach 循环传递到同一 View 中的引导模式

php - 多重连接 Laravel

javascript - 为什么这个附加仅在我控制台记录错误变量时才起作用

javascript - 为什么我的 .html 文件无法连接到 .js 文件?