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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:11:49+00:00 2026-05-24T23:11:49+00:00

Once again I need some help. I’m creating a multiple file upload function with

  • 0

Once again I need some help.
I’m creating a multiple file upload function with codeigniter and I’m stuck with the “multiple” part.
The follwing code works perfect to upload a single image, it basically uploads an regular size image to a folder and a thumbnail size version of the same image to another folder.
2 images for 2 folders, see my code:

$config['upload_path'] = './cars/large_thumb/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$config['file_name'] = $newfilename;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$uploadimages = $this->upload->do_upload();
$image_data = $this->upload->data();

$configlarge = array(
    'source_image' => $image_data['full_path'],
    'new_image' => './cars/large_thumb',
    'maintain_ratio' => true,
    'quality' => 70,
    'width' => 600,
    'height' => 450
);
$this->load->library('image_lib', $configlarge);
$this->image_lib->initialize($configlarge);
$resizelarge = $this->image_lib->resize();

$configsmall = array(
    'source_image' => $image_data['full_path'],
    'new_image' => './cars/small_thumb',
    'maintain_ratio' => true,
    'width' => 100,
    'height' => 75
);
$this->load->library('image_lib', $configsmall);
$this->image_lib->initialize($configsmall);
$resizesmall = $this->image_lib->resize();

What I need help with is the loop that that should run this code as many times as images are being uploaded.
I tried a “foreach” loop using something like this:

foreach ($_FILES["userfile"]["error"] as $key => $error)  {
    code above here...
  }  

And it gives me this error: Message: Array to string conversion
I’ve also tried a “for” loop in which I iterate through the code and it kind of works, but it uploads the last image as many times as images were being uploaded.

Hope somebody can share some knowledge with me.

Thanks

  • 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-24T23:11:52+00:00Added an answer on May 24, 2026 at 11:11 pm

    I’ve also tried a “for” loop in which I iterate through the code and it kind of works, but it uploads the last image as many times as images were being uploaded.

    It looks like you attempted to fix the problem with a for loop which was only broken because you have the incorrect naming convention for the HTML form.

    Try something like the following:

        <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="car_1" value="" />
        <input type="file" name="car_2" value="" />
        <input type="file" name="car_3" value="" />
        </form>
    

    Then in your code you can change

        $uploadimages = $this->upload->do_upload(); 
    

    to

        $uploadimages = $this->upload->do_upload('car_1'); 
    

    You should be able to enclose it in a loop to go through each image you want uploaded with the afor mentioned for loop you were using

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

Sidebar

Related Questions

Once again, I need some help and I appreciate you all for being here
Once again I need some help. I'm working with a table that contains 3
Once again I need some much appreciated help from the experts :) I am
I received some great help here the other day and hope once again I
I am once again looking for some help. I have found this stopwords script
I need your expertise once again. I have a java class that searches a
Once again I find myself failing at some really simple task in C++. Sometimes
Im working on a a sudoku program for python and i need some help.
Hey all, i am new at everything VB.net/ASP.net so i need some help with
I'm new to jQuery and need some help to show and hide a div

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.