我正在我的表单中创建一个 multiUpload 图像系统,我希望用户可以在 4 个不同的输入中上传 4 个图像并保存他们的图像,但我有这个错误:
NotReadableException in C:\xampp\htdocs\regalo\vendor\intervention\image\src\Intervention\Image\AbstractDecoder.php 第 302 行:图像源不可读
我的表格
{!! Form::open(array('url'=>'crea-regalo','method'=>'POST','class' => 'form-horizontal', 'files'=>true)) !!}
<!-- photo -->
<div class="form-group">
<label class="col-md-3 control-label" for="textarea"> Picture </label>
<div class="col-md-8">
<div class="mb10">
<input id="input-upload-img1" name="image[]" type="file" class="file" data-preview-file-type="text">
</div>
<div class="mb10">
<input id="input-upload-img2" name="image[]" type="file" class="file" data-preview-file-type="text">
</div>
<div class="mb10">
<input id="input-upload-img3" name="image[]" type="file" class="file" data-preview-file-type="text">
</div>
<div class="mb10">
<input id="input-upload-img4" name="image[]" type="file" class="file" data-preview-file-type="text">
</div>
{!! Form::close() !!}
我的控制器
foreach ($request->image as $imageArray){
// get file
$file = $request->file('image');
// create istance - Maybe here start the problem, doesn't get the files images
$image = image::make($imageArray);
// create path
$path = public_path().'/images/post/'.$get_post_created->id;
// rename file
$name_file = $get_post_created->id . '.' . $imageArray->getClientOriginalExtension();
// resize
$image->resize(100,100);
// save
$image->save($path.$name_file);
// store path reference
$store_path = new ImageUpload();
$store_path->path = 'images/post/'.$get_post_created->id.'/'.$name_file;
$store_path->post_id = $get_post_created->id;
$store_path->save();
}
我尝试上传 4 个输入的 2 个图像:
public function creaPost(Request $request){
dd ($request->image);
....
...
}
我不知道输入 name="image[]" 数组是否对文件很好,或者我的控制器中的 foreach 循环可能有问题。谢谢您的帮助!