Dropzone.js与Laravel得到500(内部服务器错误)
问题描述:
我尝试上传图像与dropzonejs库。我有关于dropzone的文档,但我得到内部服务器错误。Dropzone.js与Laravel得到500(内部服务器错误)
HTML:
<form action="http://localhost/visitingcy/public/management/create-thing"
class="dropzone"
id="my-awesome-dropzone">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
</form>
Laravel的PHP代码:
if ($request->hasFile('file')) {
$getImages = $request->input('file');
$count = 0;
$images = array();
foreach ($getImages as $img) {
$imageURL = str_slug($newThing->title) . '.' . $img->getClientOriginalExtension();
$checkForDuplicate = DB::table('things_images')->where('url', '=', $imageURL)->get();
while (!empty($checkForDuplicate)) {
$imageURL = str_slug($newThing->title) . $count . '.' . $img->getClientOriginalExtension();
$checkForDuplicate = DB::table('things_images')->where('url', '=', $imageURL)->get();
$count++;
}
$images[] = ThingImage::create(['url' => $imageURL]);
//save file to public directory
$img->move(base_path() . '/public/img/thing/gallery/', $imageURL);
}
return $images;
} else {
dd('there isnt file');
}
答
我发现这个问题。我曾使用foreach,但dropzone单独上传每个文件,所以它不需要。控制台中的500错误是因为我的控制器中有另一个功能有问题。
你能找到关于500错误的更多信息吗?也许与浏览器中的开发人员工具或存储文件夹中的laravel错误日志?我得到的laravel日志文件中的 – JackPoint
:local.ERROR:异常'ErrorException'带消息'为foreach()提供的无效参数。它说那个foreach => foreach($ getImages as $ img),因为$ getImages变量 等于null –