Note that there are some explanatory texts on larger screens.

plurals
  1. POHow come I can upload gallery images for one user, but not another?
    primarykey
    data
    text
    <p>I am creating a gallery on my website and I have created several test accounts to make sure it works for each of them. But I only seem to be able to upload any image to the screen and gallery database for only one user, and not any other. Why is this - each user has their own session so I'm very confused. Please have a look at my code. My thoughts are that there is something wrong with my putGalleryImage function in my model but I don't see anything that really sticks out at me. Im thinking it could also be in the else statement of my upload function for when an upload of an image occurs but again, nothing sticks out at me because if it works for just one specific user, why not any other?</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/'; } 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); $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; $viewData['images'] = $this-&gt;gal_model-&gt;getGalleryImage($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(); $galleryImage = $this-&gt;gallery_path.$file_data['file_name']; $data['galleryImage'] = $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, $galleryImage); $viewData['username'] = $username; $viewData['images'] = $this-&gt;gal_model-&gt;getGalleryImage($username); var_dump($galleryImage); $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', $viewData); $this-&gt;load-&gt;view('shared/footer'); } } function index() { $username = $this-&gt;session-&gt;userdata('username'); $this-&gt;load-&gt;library('upload'); $data['gal_model'] = $this-&gt;gal_model-&gt;getGalleryImage($username); $viewData['username'] = $username; $viewData['images'] = $this-&gt;gal_model-&gt;getGalleryImage($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, array('error' =&gt; ' ' )); $this-&gt;load-&gt;view('shared/footer'); } } </code></pre> <p>Model:</p> <pre><code>class Gal_model extends CI_Model { var $gallery_path; function Gal_model() { parent::__construct(); } 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; /* echo "user $user exists!"; $row = $query-&gt;row(); echo " and his profileimage is $row-&gt;profileimage"; */ } else { return false; //echo "no such user as $user!"; } } function putGalleryImage($username, $galleryImage) { $record = array('user' =&gt; $username, 'galleryimage' =&gt; $galleryImage); $this-&gt;session-&gt;set_userdata($galleryImage); if ($this-&gt;exists($username)) { $this-&gt;db-&gt;where('user', $username)-&gt;insert('gallery', $record); } } function getGalleryImage($username) { $this-&gt;db-&gt;select('*')-&gt;from('gallery')-&gt;where('user', $username); $imagesSet= $this-&gt;db-&gt;get(); $images = array(); foreach ($imagesSet-&gt;result() as $row) { $images[] = array('imageid' =&gt; $row-&gt;imageid, 'user' =&gt; $row-&gt;user, 'galleryimage' =&gt; $row-&gt;galleryimage); } return $images; } } </code></pre> <p>View:</p> <pre><code> &lt;div id="gallery"&gt; &lt;?php if (isset($images) &amp;&amp; is_array($images)): foreach($images as $galleryImage): $link = $galleryImage['galleryimage'] ?&gt; &lt;div class="thumb"&gt; &lt;img src="&lt;?php echo base_url().$link; ?&gt;" width='150' height='100'/&gt; &lt;br&gt; &lt;/div&gt; &lt;?php endforeach; else: ?&gt; &lt;div id = "blank_gallery"&gt;Please upload an Image&lt;/div&gt; &lt;?php endif; ?&gt; </code></pre> <p></p> <p></p> <pre><code> &lt;?=form_open_multipart('gallery/upload');?&gt; &lt;?=form_upload("userfile");?&gt; &lt;?=form_submit('upload', 'Upload')?&gt; &lt;?=form_close();?&gt; &lt;?php if (isset($error)) echo $error;?&gt; </code></pre> <p></p> <p>Thanks again for the help guys</p>
    singulars
    1. This table or related slice is empty.
    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.
    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