Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:41:43+00:00 2026-06-16T00:41:43+00:00

Im currently developing using codeigniter a gallery in an interactive profile where each user

  • 0

Im currently developing using codeigniter a gallery in an interactive profile where each user can upload their own section of images. Currently my view page is throwing up a Message: Undefined variable: images. This is despite I already have a get_images function in my model there also being an if statement in my view so it will understand not to try to display images if none have been uploaded yet. How can i fix this issue? Im also trying to store any image uploaded in a gallery database so that beside each user’s name it shows any image they have uploaded. Here is my code so far:

Controller:

class Gallery extends CI_Controller {



function __construct()
{
    // Call the parent construct
    parent::__construct();

    $this->load->model("profiles");
    $this->load->model("gal_model");
    $this->load->helper(array('form', 'url'));

    $this->gallery_path = 'web-project-jb/assets/gallery';
    $this->gallery_path_url = base_url().'web-project-jb/assets/gallery/';

}

function upload()
{

    $config = array(

            'allowed_types' =>'gif|jpg|jpeg|png',
            'upload_path' => $this->gallery_path,
            'max_size' => 10000,
            'max_width' => 1024,
            'max_height' => 768);

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

    $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();

    $username = $this->session->userdata('username');

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

        $username = $this->session->userdata('username');


        $viewData['username'] = $username;

        $this->load->view('shared/header');
        $this->load->view('gallery/galtitle', $viewData);
        $this->load->view('shared/nav');
        $this->load->view('gallery/galview', $error, $viewData, array('error' => ' ' ));
        $this->load->view('shared/footer');



    }
    else
    {
        $file_data  = $this->upload->data();

        $image = $this->gallery_path.$file_data['file_name'];

        $data['image'] = $this->gallery_path.$file_data['file_name'];

        $this->username = $this->session->userdata('username');

        $this->gal_model->putGalleryImage($username, $image);

        $this->session->set_userdata($image);

        $viewData['username'] = $username;
        $data['gal_model'] = $this->gal_model->get_images($username);



        $username = $this->session->userdata('username');

        $this->load->view('shared/header');
        $this->load->view('gallery/galtitle', $viewData);
        $this->load->view('shared/nav');
        $this->load->view('gallery/galview', $data, $viewData);
        $this->load->view('shared/footer');


    }
}

function index()
{

    $username = $this->session->userdata('username');

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

    $data['profileimages'] = $this->gal_model->get_images($username);

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

    $file_data['file_name'] = $this->gal_model->get_images($username);

    $image = $this->gallery_path.$file_data['file_name'];

    $data['image'] = $file_data['file_name'];


    $viewData['username'] = $username;


    $this->load->view('shared/header');
    $this->load->view('gallery/galtitle', $viewData);
    $this->load->view('shared/nav');
    $this->load->view('gallery/galview', $viewData, $data, array('error' => ' ' ));
    $this->load->view('shared/footer');

}

 }

Model:

 class Gal_model extends CI_Model
{
var $gallery_path;
var $gallery_path_url;

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

    $this->gallery_path = 'web-project-jb/assets/gallery';
    $this->gallery_path_url = base_url().'web-project-jb/assets/gallery/';
}   


function exists($username)
{
    $this->db->select('*')->from("gallery")->where('user', $username);
    $query = $this->db->get();

    if ($query->num_rows() > 0)
    {

        return true;
        /*
         echo "user $user exists!";
        $row = $query->row();
        echo " and his profileimage is $row->profileimage";
        */
    }

    else

    {

        return false;
        //echo "no such user as $user!";
    }

}



function putGalleryImage($username, $image)
{


    $record = array('user' => $username, 'galleryimage' => $image);
    $this->session->set_userdata($image);
    if ($this->exists($username))
    {
        $this->db->where('user', $username)->update('gallery', $record);


    }
    else
    {
        $this->db->where('user', $username)->insert('gallery', $record);

    }


}


function get_images($username)
{

    $this->db->select('*')->from('gal_model')->where('user', $username);

    $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;
}

  }

View:

 <?php if ( is_array($images) && (count($images)>0) ):
   foreach($images as $image): ?>
   <div class="thumb">
       <a href="<?php echo $image['url']; ?>">
          <img src ="<?php echo $image['thumb_url']; ?>"/>
       </a>  
       <br>
   </div>
<?php endforeach; else:  ?>
    <div id = "blank_gallery">Please upload an Image</div>
<?php endif; ?>

Thanks again for all the help guys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:41:44+00:00Added an answer on June 16, 2026 at 12:41 am

    You should Change your if in your view to

    if(isset($images) && is_array($images)) 
    

    that way if $images in undefined it will nto throw an error it will just skip that all together

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently developing a connector DLL to HP's Quality Center. I'm using their (insert expelative)
I am developing an website in php where user can upload csv file. after
I am currently developing a service using Java and Spring MVC where users can
I am developing a website using Codeigniter and MongoDB (Alex Bilbie library). Currently there
I am currently developing using the cxml-stp framework, but while parsing I do get
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am currently developing a site using ASP.NET MVC 3, I am using Nhibernate.
I'm currently developing a site using the WordPress Twenty Eleven theme and I would
I am currently developing my program using sample BluetoothChat program on android device. This
I am currently developing on Visual Studio 2012 RC using TFS Preview for source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.