Php Laravel多次上传仅在数据库中插入20个
我已经创建了一个API,允许多个图像上传,但是当我尝试上传超过20个时,它只会插入20个记录,一次不会再插入更多。它将在服务器上保存全部金额。没有抛出错误,日志中也没有任何指示问题的内容 我要保存到的表(事件\图像)如下所示:Php Laravel多次上传仅在数据库中插入20个,php,mysql,database,laravel,Php,Mysql,Database,Laravel,我已经创建了一个API,允许多个图像上传,但是当我尝试上传超过20个时,它只会插入20个记录,一次不会再插入更多。它将在服务器上保存全部金额。没有抛出错误,日志中也没有任何指示问题的内容 我要保存到的表(事件\图像)如下所示: id, event_id, title, path, size, extension, description, created_at, updated_at 这是我的拉威尔剧本: public function store(Request $request) {
id, event_id, title, path, size, extension, description, created_at, updated_at
这是我的拉威尔剧本:
public function store(Request $request)
{
$id = $request->id;
$images = $request->file('image');
$count = 0;
// confirm that files exists in the request
if(empty($images)):
return response()->json(['error' => 'no images exist'], 500);
endif;
// validate image(s) before we store to db to make sure there are no failures
// TODO : add to validation
$validator = Validator::make($request->all(), [
'image.*' => 'image|mimes:jpeg,jpg,png'
]);
if($validator->fails()):
return response()->json(['error' => 'upload failed, please make sure you are uploading a jpeg, jpg, or png'], 500);
endif;
// store images in DB and upload
foreach($images as $image):
$title = Uuid::uuid1();
$extension = $image->getClientOriginalExtension();
$path = $title . '.' . $extension;
$size = $image->getClientSize();
$description = NULL;
// store in db
EventsImage::Create([
'title' => $title,
'path' => $path,
'extension' => $extension,
'size' => $size,
'description' => $description,
'event_id' => $id
]);
// save to filesytem
$raw = Storage::disk('media')->put('events' . '/' . $id . '/' . $path, file_get_contents($image));
// create and store thumb
$thumb = Image::make($image)->resize(150, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('media')->put('events' . '/' . $id . '/t_' . $path, (string) $thumb->encode());
// create and store medium
$medium = Image::make($image)->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('media')->put('events' . '/' . $id . '/m_' . $path, (string) $medium->encode());
// create and store full size
// TODO : if smaller than 1920 then don't do anything
$full = Image::make($image)->resize(1920, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('media')->put('events' . '/' . $id . '/' . $path, (string) $full->encode());
$count++;
endforeach;
$event = Event::with('EventImages')->find($id);
return response()->json(['success' => true, 'message' => $count . ' images have been uploaded successfully', 'data' => $event], 200);
}
我已经查看了发送到API的数据,所有内容都在那里,所有文件都保存到光盘中。我还注释了文件保存逻辑,看看它是否是时间问题,它仍然只会插入20条记录
是否存在某种类型的限制设置?是因为我使用循环一次保存一条记录吗
编辑
我使用了Postman和Angular 4,得到了相同的结果。我上传了20多张图片,而Laravel只看到20张。您可能需要更改PHP设置以允许更大的上传量。PHP对文件上传大小、帖子大小等有限制 转到:
/etc/php5/fpm/php.ini
或/etc/php/7.0/fpm/php.ini
,或者如果您正在使用Apache/etc/php/7.0/apache2/php.ini
并更改这些值
post_max_size = 125M
upload_max_filesize = 100M
max_file_uploads = 20
到更高的值。其中
post\u max\u size
是整个post的最大大小upload\u max\u filesize
是单个大小的最大大小,max\u file\u uploads
是一次可以上载的文件的最大限制。您可能需要更改PHP设置以允许更大的上载。PHP对文件上传大小、帖子大小等有限制
转到:/etc/php5/fpm/php.ini
或/etc/php/7.0/fpm/php.ini
,或者如果您正在使用Apache/etc/php/7.0/apache2/php.ini
并更改这些值
post_max_size = 125M
upload_max_filesize = 100M
max_file_uploads = 20
到更高的值。其中,
post_max_size
是整个post的最大大小upload_max_filesize
是单个大小的最大大小,max_file_uploads
是一次可以上载的文件的最大限制。$validator=validator::make($request->all(),['image.*=>'image | mimes:jpeg,png')代码>我感觉这将检查图像的http mime类型。。你可以通过PAS上传其他文件。测试:$image=neweventsimage([…]);变量转储($image->save())代码>@JonasStaudenmeir我按照你的建议做了,我只看到20人进来。我注意到在Chromes开发工具中,我可以看到所有发送的图像。。奇怪。Laravel是否有限制有效载荷的设置?不知道为什么会这样,但我想我会问。我猜PHP.ini中的max_file_uploads
设置仍然设置为默认的OT20。@Graham没错$validator=validator::make($request->all(),['image.*=>'image | mimes:jpeg,jpg,png')代码>我感觉这将检查图像的http mime类型。。你可以通过PAS上传其他文件。测试:$image=neweventsimage([…]);变量转储($image->save())代码>@JonasStaudenmeir我按照你的建议做了,我只看到20人进来。我注意到在Chromes开发工具中,我可以看到所有发送的图像。。奇怪。Laravel是否有限制有效载荷的设置?不知道为什么会这样,但我想我会问。我猜PHP.ini中的PHP的max_file_uploads
设置仍然设置为默认的ot20。@Graham没错