我在我的表单中创建一个multiUpload图像系统,我希望用户可以在4个不同的输入上传4个图像并保存他们的图像,但我有这个错误:
中的NotReadableException C:\ XAMPP \ htdocs中\ REGALO \厂商\干预\图像\ SRC \干预\图片\ AbstractDecoder.php 第302行:图像源不可读
我的表格
<div class="photo-set col-1-1 bp2-col-1-2">
<img src="..." srcset="..."
sizes="(min-width: 29em) 50vw, 100vw">
</div>
<script>
$(".photo-set").on('click', function() {
$(this).toggleClass('full-width');
});
</script>
<style>
.bp2-col-1-2 {
width: 50%;
}
.full-width {
width: 100% !important;
}
</style>
我的控制器
{!! 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() !!}
我试过上传4个输入的2张图片:
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();
}
我不知道输入名称=&#34;图像[]&#34;数组正在变好文件,或者我的控制器在foreach循环中有一些问题。谢谢您的帮助!
答案 0 :(得分:0)
试试这个
$image = Image::make($file->getRealPath())
代替您的$image = image::make($imageArray);
然后,您可以使用图片执行所需操作,并使用代码$image->save($path.$name_file);