我想用 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/