【发布时间】:2020-04-26 16:30:44
【问题描述】:
在刀片中
<input type="file" name="image[]" id="" required class="form-control" multiple accept="image/*">
在控制器中
public function addReviewPost(Request $request)
{
$image = $request->file('image');
$this->validate($request, [
'image' => 'required',
'image.*' => ' max:2048 | dimensions:max_width=2200',
]);
if (request()->hasFile('image')) {
$counter = count($image);
for ($i = 0; $i < $counter; $i++) {
$image = Image::make($image[$i]);
$image->resize(null, 627, function ($constraint) {
$constraint->aspectRatio();
});
$image->save(public_path('../../img/testimonial/' . time() . '.png'));
}
}
}
显示错误
Symfony\Component\Debug\Exception\FatalThrowableError
Cannot use object of type Intervention\Image\Image as array
谁能帮我如何使用干预图像包上传多个文件?
【问题讨论】:
-
dd($request->all())看看图片的类型 -
0 => Illuminate\Http\UploadedFile {#291 ▼ -test: false -originalName: "93649267_10221642080937792_4082659911438172160_n.jpg" -mimeType: "image/jpeg" -error: 0 #hashName: null path: “C:\xampp\tmp” 文件名:“php19F3.tmp” 基名:“php19F3.tmp” 路径名:“C:\xampp\tmp\php19F3.tmp” 扩展名:“tmp” 真实路径:“C:\xampp\tmp \php19F3.tmp” 类型:“文件” 可写:真 可读:真 可执行:假 文件:真 dir:假 链接:假 链接目标:“C:\xampp\tmp\php19F3.tmp” }
-
这里是图像数组的输出
-
它只显示一张图片。
-
没有。它在数组中有 2 个图像。我抄了一张送给你
标签: php laravel image image-upload