我已经使用一些代码,我发现前一次上传1个图像,这完美的作品。 我想使用的代码,但是对多个图像相同的风格。
该模型:
function cover_upload($afbeelding) {
// path where the picture needs to be uploaded
echo $album_path = APPPATH . 'images/covers';
// configuration for the upload
$ext = end(explode(".", $_FILES['userfile']['name']));
$config = array(
'file_name' => $afbeelding . '.' . $ext,
'upload_path' => $album_path,
'allowed_types' => 'gif|jpg|jpeg|png',
'max_size' => '5120'
);
// load upload library with the configuration
$this->load->library('upload', $config);
// upload picture with the upload library
if (!$this->upload->do_upload()) {
echo $this->upload->display_errors();
die();
}
// get data array of the uploaded picture
$image_data = $this->upload->data();
// configuration for the picture thumbnail resize
echo $image_data['full_path'];
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => realpath($album_path . '/thumb'),
'maintain_ration' => TRUE,
'width' => 300,
'height' => 300
);
// load image manupulation library with the configuration
$this->load->library('image_lib', $config);
// resize picture
$this->image_lib->resize();
$this->image_lib->clear();
// submit file name of the uploaded picture to save it in the database
$bestandsnaam = $image_data['file_name'];
return $bestandsnaam;
}
视图(只是关于图像的部分):
<div class="form-group">
<label class="col-sm-2 control-label" for="CoverFoto">picture</label>
<div class="col-sm-5">
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"></div>
<div>
<span class="btn btn-default btn-file"><span class="fileinput-new">select_an_image</span><span class="fileinput-exists">change</span><input type="file" name="userfile"></span>
<a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput"><?php echo $this->lang->line("remove"); ?></a>
</div>
</div>
</div>
</div>
和控制器:
if (!empty($_FILES['userfile']['name'])) {
$gamma->CoverFoto = $this->gamma_model->cover_upload(url_title($gamma->Naam, '_', true));
}
是否有使用这个代码,所以我可以上传多张图片的方式?