Dropzone.js - Laravel | 500内部服务器错误
Dropzone.js - Laravel | 500 Internal Server Error
我想用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();
根据评论--
这意味着您的应用程序未在 $request->file('file')
上获取文件对象,您可以通过打印 $request
获取更多信息,然后您也可以检查文件是否从客户端脚本发送或不是
我想用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();
根据评论--
这意味着您的应用程序未在 $request->file('file')
上获取文件对象,您可以通过打印 $request
获取更多信息,然后您也可以检查文件是否从客户端脚本发送或不是