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

  • Home
  • SEARCH
  • 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 6759519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:57:08+00:00 2026-05-26T13:57:08+00:00

Firstly, I’m not asking how to perform a multi-file upload using CodeIgniter, but rather

  • 0

Firstly, I’m not asking how to perform a multi-file upload using CodeIgniter, but rather how to prevent any/all files from being uploaded if the last one in line fails (due to filetype, size, etc.). Basically I’m looking to use CI’s file validation up front (before anything is uploaded), and if everything looks good, perform all uploads.

I have a form that uploads two files. If the first file passes validation and the do_upload() method returns TRUE, but the second file fails, the first file was still uploaded — how can I prevent this?

Here’s my code:

// Controller

function upload_files()
{

    // Configure first file upload  
    $config['upload_path']          = 'public/mp3/';
    $config['overwrite']            = FALSE;
    $config['allowed_types']        = 'mp3';
    $config['max_size']             = '20000';
    $config['remove_spaces']        = TRUE;

    $this->upload->initialize($config);

    // Perform first file upload
    if ($this->upload->do_upload('mp3'))
    {
        // Store upload file info for later use
        $mp3_info = $this->upload->data();

        // Configure second file upload
        $config['upload_path']          = 'public/doc/';
        $config['overwrite']            = FALSE;
        $config['allowed_types']        = 'doc|docx';
        $config['max_size']             = '3000';
        $config['remove_spaces']        = TRUE;
        $this->upload->initialize($config);

        // Perform second file upload
        // Even if this fails, the first file was still uploaded
        if ($this->upload->do_upload('doc'))
        {
            // Store upload file info for later use
            $doc_info = $this->upload->data();

            // Perform database interactions here
        }
        else
        {
            echo $this->upload->display_errors();
        }
    }
    else
    {
        echo $this->upload->display_errors();
    }
}
  • 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-26T13:57:08+00:00Added an answer on May 26, 2026 at 1:57 pm

    No dice! You can’t validate an upload from php or codeigniter unless you execute the upload. How can php validate something it doesn’t yet have access to?

    You have to do some validation up-front with javascript. If all files pass the js validation, then upload the files and complete validation with php/codeigniter.

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

Sidebar

Related Questions

Firstly, I do not have any malicious intent out of this question. I would
(Firstly, as a disclaimer, this is related to an assignment. I'm not asking anyone
Firstly, I'm starting to use StructureMap, but an example in any DI framework will
Firstly I tried fiding some similar posts but could not quite find anything. Mainly
Firstly, I'm rather new to SQL and I've run into a roadblock. I'm using
Firstly, i am sorry if the title does not properly describe my problem, but
Firstly, I have search Stack Overflow for the answer, but I have not found
Firstly, if you're not using 9.1+, please refer to this question . How do
Firstly, I want to apologize for my English, not my strongest side. To the
Firstly, I know I should be using proper Threading techniques (Threadpool, BeginInvoke, etc.) to

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.