尝试使用Intervention\Image制作照片上传器 我在ReportController @ store中有这个:
public function SavePhoto($photo){
$file_ext = $photo->getClientOriginalExtension();
$file_name = uniqid();
$photo_name = $file_name. '.' . $file_ext;
$path = public_path('uploads/photos/' . $photo_name);
Image::make($photo)->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
})->save($path);
return $photo_name;
}
public function store(Request $request)
{
$observation = new Observation();
$observation->content = $request['Observation'];
$observation->status_id = $request['Status'];
$photo = Input::file('photo');
foreach ($photo as $p){
$this->SavePhoto($p);
}
我对如何为所有照片输入调用SavePhoto()方法感到困惑。
答案 0 :(得分:1)
根据Laravel API文档,使用allFiles()方法获取$request
的文件。
$photos = $request->allFiles();
foreach ($photos as $photo){
$this->SavePhoto($photo);
}
我还没试过。 :)
它相当于获取$ _FILES数组
foreach($_FILES as $photo) {
$this->SavePhoto($photo);
}