【发布时间】:2013-12-06 10:20:54
【问题描述】:
大家
我在图像显示、操作和缩略图创建方面遇到问题。我的图像上传正常,它存储在 uploads 文件夹中,然后存储在 thumbs 文件夹中。现在我想在视图页面中一起显示这些图像。这是我的代码。请,请帮助我。我正在等待。提前谢谢。
这是我的控制器(画廊)
<?php
class gallery extends CI_Controller
{
function gallery()
{
parent::__construct();
$this->load->model('Gallery_Model');
}
function index()
{
if ($this->input->post('upload')){
$this->Gallery_Model->do_upload();
}
$data['images'] = $this->Gallery_Model->get_images();
$this->load->view('gallery_view',$data);
}
}
这是我的模型(gallery_model)
<?php
class Gallery_Model extends CI_Model
{
var $gallery_path;
var $gallery_path_2;
function Gallery_Model()
{
parent::__construct();
$this->gallery_path=realpath(APPPATH . '../uploads');
$this->gallery_path_2=base_url() .'uploads';
}
function do_upload()
{
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path .'/thumbs',
'maintain_ration' =>true,
'width' =>150,
'height' =>100
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
function get_images()
{
$files= scandir($this->gallery_path);
$files= array_diff($files, array(',',',','thumbs'));
$images = array();
foreach ($files as $file)
{
$images[]=array(
'url' =>$this->gallery_path_2 . $file,
'thumb_url' =>$this->gallery_path_2 .'thumbs/'. $file,
);
}
return $images;
}
}
【问题讨论】:
标签: javascript php jquery image codeigniter