我应该如何显示图像的拇指?其中形象店db和拇指店在文件夹

我应该如何显示图像的拇指?其中形象店db和拇指店在文件夹

问题描述:

我控制器我应该如何显示图像的拇指?其中形象店db和拇指店在文件夹

<?php class Image_control extends CI_Controller{ 
var $gallery_path; 
var $gallery_path_url; 
function index() 
{ 
    $this->load->view('image_view'); 
    //$this->do_upload(); 
} 

function __construct() 
{ 
    parent::__construct(); 

    $this->gallery_path= realpath(APPPATH . '../images1'); 
    $this->gallery_path_url=base_url().'images1/'; 
} 

function do_upload() 
{ 
    if($this->input->post('upload')) 
    { 
    $config = array(
     'allowed_types' => 'jpg|png|bmp', 
     'upload_path'=>$this->gallery_path, 
     'max_size'=>2000 
    ); 
    //echo $this->gallery_path; 

    $this->load->library('upload',$config); 

    if (!$this->upload->do_upload()) { 
     $errors[]=array('error'=>$this->upload->display_errors()); 
     $this->load->view('image_view',$errors); 
     //echo print_r($error); 
    } 

    $image_path=$this->upload->data(); 
    $file_name=$image_path['file_name']; 
    //$full_path=$image_path['full_path']; 

    $config = array(
     'a_name' => $this->input->post('a_name'), 
     'a_details'=>$this->input->post('a_info'), 
     'a_photo'=>$file_name 
    ); 

    $insert=$this->db->insert('animalstore',$config); 
    //return $insert; 

    $image_data=$this->upload->data(); 

    $config = array(
     'source_image' => $image_data['full_path'], 
     'new_image'=>$this->gallery_path . './thumbs', 
     'maintain_ration'=>true, 
     'width'=>100, 
     'height'=>100 
    ); 

    $this->load->library('image_lib',$config); 
    $this->image_lib->resize(); 

    $this->thumb_view(); 
    $this->image_view(); 

    //$this->load->view('image_view'); 
} 
} 

function get_thumbs() 
{ 
    $files=scandir($this->gallery_path); 
    $files=array_diff($files,array('.','..','thumbs')); 

    $images = array(); 

    foreach ($files as $file) { 
     $images[] = array(
      //'url' =>$this->gallery_path_url .$file, 
      'thumb_url'=>$this->gallery_path_url .'thumbs/'.$file 
     ); 
    } 

    return $images; 
} 

function thumb_view() 
{ 
    $data['thumbs']=$this->get_thumbs(); 
    $this->load->view('image_view',$data); 
} 

function get_images() 
{ 
    $query = $this->db->get('animalstore'); 

    /*$files=scandir($this->gallery_path); 
    $files=array_diff($files,array('.','..','thumbs')); 
    $images = array();*/ 

    if($query->num_rows() > 0) 
    { 
     foreach($query->result() as $rows) 
     { 
      /*$images[] = array(
       'url' => $this->gallery_path_url . $rows['url'], 
       'thumb_url' => $this->gallery_path_url . 'thumbs/' . $rows['url'] 
      );*/ 
      $data[] = $rows; 
     } 
     return $data; 
     //return $images; 
    } 

} 

function image_view() 
{ 
    $data['images']=$this->get_images(); 
    $this->load->view('image_view',$data); 
}}?> 

我看来

<html><body> 
<?php 
    echo form_open_multipart('image_control/do_upload'); 
    echo form_input('a_name','Animal Name'); 
    echo form_input('a_info','Animal Information'); 
    echo form_upload('userfile'); 
    echo form_submit('upload','Upload'); 
    echo form_close(); 
?> 

<?php if(isset($images) && count($images)): ?> 
    <?php foreach ($images as $image):?>     
     <h1><?php echo $image->a_name;?></h1> 
     <h1><?php echo $image->a_details;?></h1> 
     <a href="http://localhost/ci_test/images1/<?php echo $image->a_photo;?>"> 
      <img src="<?php echo $thumb['thumb_url'];?>"/> 
     </a>    
    <?php endforeach; ?> 
<?php else: ?> 
    <div id="blank_gallery">Please Upload an image</div> 
<?php endif;?> 

我将图像存储在数据库中,并在一个文件夹中。我想通过点击图像的缩略图从数据库中检索图像。缩略图存储在文件夹中。错误是我无法显示缩略图它说“未定义的变量拇指”。我应该如何显示图像的拇指?我在很多方面尝试过,但无法获得结果。 在此先感谢。

+0

不将图像存储在数据库,除非你有一个真正的特定需要 – 2013-07-10 21:44:47

+0

EM JST在DB @Dagon – brijeshp09

您还没有image_view()

传递$thumbs有很多方法你的代码可以得到改善,更好的实践遵循 - 但在回答你的问题,与下面将清除错误更换image_view()的利益:

function image_view() 
{ 
    $data['thumbs']=$this->get_thumbs(); 
    $data['images']=$this->get_images(); 
    $this->load->view('image_view',$data); 
} 
+0

其仍显示误差为未定义索引存储图像名称:thumb_url。 – brijeshp09