Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy aren't my gallery images not displaying on my page when I upload them?
    primarykey
    data
    text
    <p>I'm currently trying to upload images to a page and also have them saved within 2 folders. What's supposed to happen is I upload an image and it is saved in my gallery and thumbs folder. </p> <p>The image saved in the thumbs folder will then be displayed on the screen and when the image is clicked on, it will be displayed in its proper size, as it was saved in the gallery folder. At the moment the image is saved to the gallery database and to my gallery folder but the thumb image does not display on the screen.</p> <p>I think is because it's not saved to the thumbs folder. Why is it not saved to the folder? </p> <p>Controller:</p> <pre><code>class Gallery extends CI_Controller { function __construct() { // Call the parent construct parent::__construct(); $this-&gt;load-&gt;model("profiles"); $this-&gt;load-&gt;model("gal_model"); $this-&gt;load-&gt;helper(array('form', 'url')); $this-&gt;gallery_path = 'web-project-jb/assets/gallery/'; $this-&gt;gallery_path_url = base_url().'web-project-jb/assets/gallery/'; } function upload() { $config = array( 'allowed_types' =&gt;'gif|jpg|jpeg|png', 'upload_path' =&gt; $this-&gt;gallery_path, 'max_size' =&gt; 10000, 'max_width' =&gt; 1024, 'max_height' =&gt; 768); $this-&gt;load-&gt;library('upload', $config); $image_data = $this-&gt;upload-&gt;data(); $config = array( 'source_image' =&gt; $image_data["full_path"], 'new_image' =&gt; $this-&gt;gallery_path. '/thumbs', 'maintain_ration' =&gt; true, 'width' =&gt; 150, 'height' =&gt; 100 ); $this-&gt;load-&gt;library("image_lib", $config); $this-&gt;image_lib-&gt;resize(); $username = $this-&gt;session-&gt;userdata('username'); if ( ! $this-&gt;upload-&gt;do_upload()) { $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors()); $username = $this-&gt;session-&gt;userdata('username'); $viewData['username'] = $username; $this-&gt;load-&gt;view('shared/header'); $this-&gt;load-&gt;view('gallery/galtitle', $viewData); $this-&gt;load-&gt;view('shared/nav'); $this-&gt;load-&gt;view('gallery/galview', $error, $viewData, array('error' =&gt; ' ')); $this-&gt;load-&gt;view('shared/footer'); } else { $file_data = $this-&gt;upload-&gt;data(); $image = $this-&gt;gallery_path.$file_data['file_name']; $data['image'] = $this-&gt;gallery_path.$file_data['file_name']; $this-&gt;username = $this-&gt;session-&gt;userdata('username'); $images = $this-&gt;session-&gt;userdata('images'); $data['images'] = $images; $this-&gt;gal_model-&gt;putGalleryImage($username, $image); $this-&gt;session-&gt;set_userdata($image); $viewData['username'] = $username; $data['gal_model'] = $this-&gt;gal_model-&gt;get_images($username); var_dump($image); $username = $this-&gt;session-&gt;userdata('username'); $this-&gt;load-&gt;view('shared/header'); $this-&gt;load-&gt;view('gallery/galtitle', $viewData); $this-&gt;load-&gt;view('shared/nav'); $this-&gt;load-&gt;view('gallery/galview', $data, $viewData); $this-&gt;load-&gt;view('shared/footer'); } } function index() { $username = $this-&gt;session-&gt;userdata('username'); $images = $this-&gt;session-&gt;userdata('images'); $this-&gt;load-&gt;library('upload'); $data['gal_model'] = $this-&gt;gal_model-&gt;get_images($username); $file_data = $this-&gt;upload-&gt;data(); $file_data['file_name'] = $this-&gt;gal_model-&gt;get_images($username); $image = $this-&gt;gallery_path.$file_data['file_name']; $data['image'] = $file_data['file_name']; $data['images'] = $images; $viewData['username'] = $username; $this-&gt;load-&gt;view('shared/header'); $this-&gt;load-&gt;view('gallery/galtitle', $viewData); $this-&gt;load-&gt;view('shared/nav'); $this-&gt;load-&gt;view('gallery/galview', $viewData, $data, array('error' =&gt; ' ')); $this-&gt;load-&gt;view('shared/footer'); } } </code></pre> <p>Gal model:</p> <pre><code>class Gal_model extends CI_Model { var $gallery_path; var $gallery_path_url; function Gal_model() { parent::__construct(); $this-&gt;gallery_path = 'web-project-jb/assets/gallery/'; $this-&gt;gallery_path_url = base_url().'web-project-jb/assets/gallery/'; } function exists($username) { $this-&gt;db-&gt;select('*')-&gt;from("gallery")-&gt;where('user', $username); $query = $this-&gt;db-&gt;get(); if ($query-&gt;num_rows() &gt; 0) { return true; } else { return false; } } function putGalleryImage($username, $image) { $record = array('user' =&gt; $username, 'galleryimage' =&gt; $image); $this-&gt;session-&gt;set_userdata($image); if ($this-&gt;exists($username)) { $this-&gt;db-&gt;where('user', $username)-&gt;insert('gallery', $record); } } function get_images($username) { $this-&gt;db-&gt;select('*')-&gt;from('gal_model')-&gt;where('user', $username); $files = scandir($this-&gt;gallery_path); $files = array_diff($files, array('.', '..', 'thumbs')); $images = array(); foreach ($files as $file) { $images[] = array( 'url' =&gt; $this-&gt;gallery_path_url.$file, 'thumb_url' =&gt; $this-&gt;gallery_path_url.'thumbs/'.$file ); } return $images; } } </code></pre> <p>Gallery view:</p> <pre><code>&lt;? if (isset($images) &amp;&amp; is_array($images)): foreach($images as $image):?&gt; &lt;a href="&lt;?php echo $image['url']; ?&gt;"&gt; &lt;img src ="&lt;?php echo $image['thumb_url']; ?&gt;"width='150' height='150'/&gt; &lt;?= endforeach; else: ?&gt; &lt;div id = "blank_gallery"&gt;Please upload an Image&lt;/div&gt; &lt;? endif; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload