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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:04:36+00:00 2026-05-26T04:04:36+00:00

I want use from multiple upload image in codeigniter but problem is here that

  • 0

I want use from multiple upload image in codeigniter but problem is here that if if don’t select image for upload return is false in case i want if don’t select image for upload it redirect to my url(just ignore from error required select file). how can fix it in function go_upload?

My function:

<?php
function go_upload($field = 'userfile')
{
    $CI =& get_instance();
    // Is $_FILES[$field] set? If not, no reason to continue.
    if (!isset($_FILES[$field]['name'][0])) {
        $CI->upload->set_error('upload_no_file_selected');
        return FALSE;
    } else {
        $num_files    = count($_FILES[$field]['name']) - 1;
        $file_list    = array();
        $error_hold   = array();
        $error_upload = FALSE;
    }

    // Is the upload path valid?
    if (!$CI->upload->validate_upload_path()) {
        // errors will already be set by validate_upload_path() so just return FALSE
        return FALSE;
    }

    for ($i = 0; $i < $num_files; $i++) {
        //            $fname = $_FILES[$field]['name'][$i];
        //            echo "$fname\n\n<br><br>\n\n";

        $error_hold[$i] = FALSE;

        // Was the file able to be uploaded? If not, determine the reason why.
        if (!is_uploaded_file($_FILES[$field]['tmp_name'][$i])) {
            $error = (!isset($_FILES[$field]['error'][$i])) ? 4 : $_FILES[$field]['error'][$i];

            switch ($error) {
                case 1: // UPLOAD_ERR_INI_SIZE
                    $error_hold[$i] = 'upload_file_exceeds_limit';
                    break;
                case 2: // UPLOAD_ERR_FORM_SIZE
                    $error_hold[$i] = 'upload_file_exceeds_form_limit';
                    break;
                case 3: // UPLOAD_ERR_PARTIAL
                    $error_hold[$i] = 'upload_file_partial';
                    break;
                case 4: // UPLOAD_ERR_NO_FILE
                    $error_hold[$i] = 'upload_no_file_selected';
                    break;
                case 6: // UPLOAD_ERR_NO_TMP_DIR
                    $error_hold[$i] = 'upload_no_temp_directory';
                    break;
                case 7: // UPLOAD_ERR_CANT_WRITE
                    $error_hold[$i] = 'upload_unable_to_write_file';
                    break;
                case 8: // UPLOAD_ERR_EXTENSION
                    $error_hold[$i] = 'upload_stopped_by_extension';
                    break;
                default:
                    $error_hold[$i] = 'upload_no_file_selected';
                    break;
            }

            return FALSE;
        }

        // Set the uploaded data as class variables
        $CI->upload->file_temp = $_FILES[$field]['tmp_name'][$i];
        $CI->upload->file_name = $CI->upload->file_name = $_FILES[$field]['name'][$i];
        $CI->upload->file_size = $_FILES[$field]['size'][$i];
        $CI->upload->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type'][$i]);
        $CI->upload->file_type = strtolower($CI->upload->file_type);
        $CI->upload->file_ext  = $CI->upload->get_extension($_FILES[$field]['name'][$i]);

        // Convert the file size to kilobytes
        if ($CI->upload->file_size > 0) {
            $CI->upload->file_size = round($CI->upload->file_size / 1024, 2);
        }

        // Is the file type allowed to be uploaded?
        if (!$CI->upload->is_allowed_filetype()) {
            $error_hold[$i] = 'upload_invalid_filetype';
        }

        // Is the file size within the allowed maximum?
        if (!$CI->upload->is_allowed_filesize()) {
            $error_hold[$i] = 'upload_invalid_filesize';
        }

        // Are the image dimensions within the allowed size?
        // Note: This can fail if the server has an open_basdir restriction.
        if (!$CI->upload->is_allowed_dimensions()) {
            $error_hold[$i] = 'upload_invalid_dimensions';
        }

        // Sanitize the file name for security
        $CI->upload->file_name = $CI->upload->clean_file_name($CI->upload->file_name);

        // Remove white spaces in the name
        if ($CI->upload->remove_spaces == TRUE) {
            $CI->upload->file_name = preg_replace("/\s+/", "_", $CI->upload->file_name);
        }

        /*
         * Validate the file name
         * This function appends an number onto the end of
         * the file if one with the same name already exists.
         * If it returns false there was a problem.
         */
        $CI->upload->orig_name = $CI->upload->file_name;

        if ($CI->upload->overwrite == FALSE) {
            $CI->upload->file_name = $CI->upload->set_filename($CI->upload->upload_path, $CI->upload->file_name);

            if ($CI->upload->file_name === FALSE) {
                $error_hold[$i] = TRUE;
            }
        }

        /*
         * Move the file to the final destination
         * To deal with different server configurations
         * we'll attempt to use copy() first.  If that fails
         * we'll use move_uploaded_file().  One of the two should
         * reliably work in most environments
         */
        if (!@copy($CI->upload->file_temp, $CI->upload->upload_path . $CI->upload->file_name)) {
            if (!@move_uploaded_file($CI->upload->file_temp, $CI->upload->upload_path . $CI->upload->file_name)) {
                $error_hold[$i] = 'upload_destination_error';
            }
        }

        /*
         * Run the file through the XSS hacking filter
         * This helps prevent malicious code from being
         * embedded within a file.  Scripts can easily
         * be disguised as images or other file types.
         */
        if ($CI->upload->xss_clean == TRUE) {
            $CI->upload->do_xss_clean();
        }

        if ($error_hold[$i]) {
            $error_upload = TRUE;

            //                echo $error_hold[$i];
        } else {
            if ($imageVar = $this->multiple_image_properties($CI->upload->upload_path . $CI->upload->file_name)) {
                $file_list[] = array(
                    'name' => $CI->upload->file_name,
                    'file' => $CI->upload->upload_path . $CI->upload->file_name,
                    'size' => $CI->upload->file_size,
                    'ext' => $CI->upload->file_ext,
                    'image_type' => $imageVar->image_type,
                    'height' => $imageVar->height,
                    'width' => $imageVar->width
                );
            } else {
                $file_list[] = array(
                    'name' => $CI->upload->file_name,
                    'file' => $CI->upload->upload_path . $CI->upload->file_name,
                    'size' => $CI->upload->file_size,
                    'type' => $CI->upload->file_type,
                    'ext' => $CI->upload->file_ext
                );
            }
        }

        // For debugging

        /*            
        if (strlen($error_hold[$i]) > 1) {
        print_r($error_hold);
        }
        */
    } // end for loop

    // Add error display for individual files        
    if ($error_upload) {
        $this->set_error($error_hold);
        return FALSE;
    } else {
        return $file_list;
    }
}
?>

My CI_Controller:

$config['upload_path'] = './uploads/'; // server directory
$config['allowed_types'] = 'gif|jpg|png'; // by extension, will check for whether it is an image
$config['max_size']    = '1000'; // in kb
$config['max_width']  = '1024';
$config['max_height']  = '768';

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

$files = $this->multi_upload->go_upload();    
if ( ! $files )
{
    $error = array('error' => $this->upload->display_errors());                         
    print_r($error);
    return false;
}
else
{
$data3 = array();
foreach ($files as $idx => $name) {
    //var_dump($name['name']);
    $data3[] = array(
        'relation' => $query_hi->id,
        'images' => $name['name'],
    );
};
}
$this->db->insert_batch('hotel_image', $data3);
redirect('admin/residence/insert');
  • 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-26T04:04:37+00:00Added an answer on May 26, 2026 at 4:04 am

    I would try taking a look at what in inside of the.

    $_FILES
    

    Array, that is the array that php starts when a post forum also has an image. If your controller checks there to make sure there is an image or not should be a good way to avoid that error.

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

Sidebar

Related Questions

I use codeigniter. I want multiple upload image, for this work, i use library
I want to use some functions from a .cpp source file that has a
I want to use a table valued function and call it from within multiple
I have a simple form that I don't want accidentally submitted multiple times. I
I'm trying to use SQL to delete multiple rows from multiple tables that are
I have a form with multiple input fields, but only want to use one
I want to receive multi file post from image uploader.( i use this )
I want to select rows from multiple tables using subsonic. For one table I
I'm building a website where users can upload images. I don't want to use
i want use some data from a website with web service. i have a

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.