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 4537100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:37:39+00:00 2026-05-21T14:37:39+00:00

I have the following code witch I have just found out that I can

  • 0

I have the following code witch I have just found out that I can upload any kind of file (.png.jpg .txt etc) but I am also unsure were to place $data[success] = TRUE so that it shows after the page has been reloaded and the functions have been run. How could I also do this with the error messages if there was an error?

Controller:

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Addimage extends CI_Controller { 

    function __construct(){ 
    parent::__construct(); 
    } 
    function index() { 
    if(!$this->session->userdata('logged_in')) { 
        redirect('admin/home'); 
    } 
    // Main Page Data 
    $data['cms_pages'] = $this->navigation_model->getCMSPages(); 
    $data['title'] = 'Add Gallery Image'; 
    $data['content'] = $this->load->view('admin/addimage',NULL,TRUE); 

    $this->load->view('admintemplate', $data); 

    //Set Validation 
    //$this->form_validation->set_rules('userfile', 'userfile', 'trim|required'); 
    $this->form_validation->set_rules('description', 'Description', 'trim|required'); 

    if($this->form_validation->run() === TRUE) { 

    //Set File Settings 
    $config['upload_path'] = 'includes/uploads/gallery/'; 
    $config['allowed_types'] = 'jpg|png'; 
    $config['remove_spaces'] = TRUE;
    $config['overwrite'] = TRUE;
    $config['max_size'] = '100'; 
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768'; 

    $this->load->library('upload', $config); 
    if(!$this->upload->do_upload()) {

    $error = array('imageError' => $this->upload->display_errors());
    }
    else{
    $data = array('upload_data' => $this->upload->data());
    $data['success'] = TRUE;
    $config['image_library'] = 'GD2';
    $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
    $config['new_image'] = 'includes/uploads/gallery/thumbs/';
    $config['create_thumb'] = 'TRUE';
    $config['thumb_marker'] ='_thumb';
    $config['maintain_ratio'] = 'FALSE';
    $config['width'] = '200';
    $config['height'] = '150';

    $this->load->library('image_lib', $config);
    $this->image_lib->resize();
    }

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

    $data = array(   
        'description' => $this->input->post('description', TRUE), 
        'imagename' => $file_info['file_name'],
    'thumbname' =>$file_info['raw_name'].'_thumb'.$file_info['file_ext'] 
        ); 
    $this->image_model->addImage($data);

    } 
 } 

}

View:

<?php
//Setting form attributes
$formAddImage = array('id' => 'addImage', 'name' => 'addImage');
$imageImage = array('id' => 'userfile', 'name' => 'userfile', 'placeholder' => 'File Location*');
$imageDescription = array('id' => 'description','name' => 'description','placeholder' => 'Image Description*');

if($success == TRUE) {
echo '<section id = "validation">Image Uploaded</section>'; 
}


?>


<section id = "validation"><?php echo validation_errors();?></section>


<?php
echo form_open_multipart('admin/addimage', $formAddImage);
echo form_fieldset();
echo form_upload($imageImage);
echo form_textarea($imageDescription);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?>
  • 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-05-21T14:37:39+00:00Added an answer on May 21, 2026 at 2:37 pm
    if(!$this->upload->do_upload()) {
    
        $status = array('imageError' => $this->upload->display_errors());
    }
    else 
    {
        $status = 'Success message'; // or just true
        // etc
    }
    

    then in your view:

    if($status==TRUE) 
    { 
        // your success
    } 
    else 
    {
       // aw..somethings's gone wrong, print_r($status);
    {
    

    So essentially use one variable.

    This is also a good example of when to use flashdata, which is exactly for these purposes.

    if(!$this->upload->do_upload()) 
    {
        $this->session->set_flashdata('message', 'Sorry, error...');
    } 
    else 
    {
        $this->session->set_flashdata('message', 'Success!');
    }
    

    You can of course pass your array of data to set_flashdata if needed.

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

Sidebar

Related Questions

I am working with NSCache in iOS i have following code in .h file
I have the following code: <div id=slideshow > <div class=check> <img src=images/slideshow/image01.jpg alt=Slideshow Image
Edit: Just found out this is a chrome problem, the code works fine in
I have the following Spring code, taken from a textbook, that's returning a NotWritablePropertyException.
I just found out that the Page Controller is being used by default when
I Have following code with LINQ var q = (from web in DataContext.Webs select
I have the following code with a bool if statement inside and in another
Hi I have the following code with jQuery: function reject(id) { $.ajax({ type: 'POST',
I have the following html code with Jquery Sorting <div class=sortable style='width:700px; margin: 0
The following code with alternating background I have shows up fine in Chrome and

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.