【问题标题】:Image upload and Image manipulation in Codeigniter is not workingCodeigniter 中的图像上传和图像操作不起作用
【发布时间】: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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 2017-08-21
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多