Codeigniter中的图像上传和图像处理无效

时间:2013-12-06 10:20:55

标签: javascript php jquery image codeigniter

大家

我正面临着图像显示,操作和缩略图创建的问题。我的图像上传还可以,它存储在uploads文件夹然后是thumb文件夹。现在我想在视图页面中一起显示这些图像。这是我的代码。拜托,请帮帮我。我在等。谢谢。

这是我的控制器(图库)

<?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;

}

}

1 个答案:

答案 0 :(得分:0)

在您看来,尝试这样的事情:

<?php foreach($images as $image){?>
<img src="<?php echo $images['url'];?>" />
<?php } ?>

为缩略图做类似的事情。我不知道你的观点是什么样的,所以我不能给你任何细节。