我已经查看mycode一个小时了,但我真的找不到我的代码有什么问题。当我上传3张图像时,它只保存2张,而4张是3张,以此类推,所以这是我的代码:
控制器
if(Input::hasFile('images'))
{
$file = Input::file('images');
foreach($file as $files) {
$img = Image::make($files)->resize(300, 240);
$lgimg = Image::make($files);
$name = time().'-'.'chicken.jpg';
$img->save('images/chickens/thumbs/'.$name,30);
$lgimg->resize(800, null, function ($constraint) {
$constraint->aspectRatio();
});
$lgimg->save('images/chickens/'.$name,60);
$newimage = new Photo;
$newimage->chicken_id=$idinsert;
$newimage->photo_loc=$name;
$newimage->save();
}
}
视图
{{ Form::label('tuimg','Upload Image')}}
{{ Form::file('images[]', array('multiple'=>true)) }}
请帮忙。感谢
发现问题,是文件名没有改变,这就是为什么照片总是缺少,它使用相同的文件名,因为我在使用时间。为了进一步解释,这里是代码
if(输入::hasFile('images')){
$file = Input::file('images');
//we need to a changing value on every save
$myarray=0;
foreach($file as $files) {
$img = Image::make($files)->resize(300, 240);
$lgimg = Image::make($files);
$name = time().'-'.$myarray.'chicken.jpg';
$img->save('images/chickens/thumbs/'.$name,30);
$lgimg->resize(800, null, function ($constraint) {
$constraint->aspectRatio();
});
$lgimg->save('images/chickens/'.$name,60);
$newimage = new Photo;
$newimage->chicken_id=$idinsert;
$newimage->photo_loc=$name;
$newimage->save();
$myarray++;
}
}