![]() |
CodeIgniter from Scratch: Day 9 Tutorial Problems displaying images - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CodeIgniter from Scratch: Day 9 Tutorial Problems displaying images (/showthread.php?tid=47917) |
CodeIgniter from Scratch: Day 9 Tutorial Problems displaying images - El Forum - 12-28-2011 [eluser]Unknown[/eluser] Hi, I've been following the codeigniter from scratch tutorial on how to upload and display images and found them very worthwhile, however I have been having issues with the displaying images section of the tutorial. The files upload without issue to the correct folder but I cannot make them display. I believe the function getimages is not working correctly in my code but I'm not sure how to fix it. http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-file-uploading-and-image-manipulation/ Can anyone see where I am going wrong? Any help is greatly appreciated!! My config file looks as follows $config['index_page'] = 'lab06_spacebook.php'; My .htaccess file is as follows RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ lab06_spacebook.php?/$1 [L] Heres a copy of my code 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 .'../lab06_spacebook/assets'); $this->gallery_path_2=base_url() .'assets'; } 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; } } __________________________________________________________________________________________ View __________________________________________________________________________________________ <div class="container_12"> <div class="grid_7 prefix_3"> <div class="grid_2 alpha"> <h2> Photo Gallery </h2> </div> <div class="grid_3"> <div id = "gallery"> <?php if (isset($images) && count($images)): foreach($images as $image): ?> <div class="thumb"> <a href="<?php echo $image['url']; ?>"> <img src= "<?php echo $image['thumb_url']; ?>"/> </a> <?php endforeach; else: ?> <div id = "blank_gallery"> Please Upload an Image</div> <?php endif ?> </div> <div class="grid_2 omega"> <div id = "upload"> <?php echo form_open_multipart('gallery'); echo form_upload('userfile'); echo form_submit('upload', 'Upload'); echo form_close(); ?> </div> ___________________________________________________________________________________________ Controller ___________________________________________________________________________________________ <?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(); } $viewData['username'] =$this->session->userdata('UserName'); $data['images'] = $this->Gallery_Model->get_images(); $this->load->view('shared/header'); $this->load->view('gallery/gallerytitle'); $this->load->view('gallery/galleryview',$viewData,$data); $this->load->view('shared/footer'); } } |