Welcome Guest, Not a member yet? Register   Sign In
Upload multiple files
#1

(This post was last modified: 02-13-2018, 09:43 PM by Elias.)

Hi,

I want to do upload multiple files and  I can do this in cycle.

But first I looked source code of Upload library and found the part of the library code. And I can't understand this code. What does this code?

P.S: If my file field in form has name user[photo] and in do_upload() I passing user while file not selected (empty form submitted) that I get a PHP error:
Code:
Severity: Warning
Message: is_uploaded_file() expects parameter 1 to be string, array given
Filename: libraries/Upload.php
Line Number: 412
instead of a CI message about file not selected.

  1. How can I upload a few files without a cycle?
  2. How can I upload a file with field name like user[photo]?
  3. Why do I have error in the case with empty form? Is it a bug with unhandled error?
  4. What does the code by link above?
Thanks!
Reply
#2

Google is your friend Search...

CodeIgniter Multi-Upload
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(02-13-2018, 06:09 AM)Elias Wrote: Hi,

I want to do upload multiple files and  I can do this in cycle.

But first I looked source code of Upload library and found the part of the library code. And I can't understand this code. What does this code?

It handles array-notation field names, as the comment line there says.

(02-13-2018, 06:09 AM)Elias Wrote: P.S: If my file field in form has name user[photo] and in do_upload() I passing user while file not selected (empty form submitted) that I get a PHP error:
Code:
Severity: Warning
Message: is_uploaded_file() expects parameter 1 to be string, array given
Filename: libraries/Upload.php
Line Number: 412
instead of a CI message about file not selected.

Why are you passing 'user' if the field is 'user[photo]'? Why would you ever expect that to work?

(02-13-2018, 06:09 AM)Elias Wrote:
  1. How can I upload a few files without a cycle?
  2. How can I upload a file with field name like user[photo]?
  3. Why do I have error in the case with empty form? Is it a bug with unhandled error?
  4. What does the code by link above?
Thanks!

1. You can't, and you shouldn't - that's what loops are made for.
2. Pass 'user[photo]' instead of 'user' ...
3. If you're referring to the error mentioned above - already answered; if not, then I don't know what you're talking about.
4. It allows you to write 'user[photo]'.
Reply
#4

(02-14-2018, 11:18 AM)Narf Wrote: 2. Pass 'user[photo]' instead of 'user' ...

Ok, in my controller I do this:
PHP Code:
$uploaded = [];

for(
$i 0$i 3$i++)
{
    if ( 
$this->upload->do_upload("userfile[$i]") )
    {
        
$uploaded[] = $this->upload->data('file_name');
    }
    else
    {
        break;
    }

while in my view I have this:
Code:
        <?= form_open_multipart('uploader') ?>

            <fieldset>
                <?= form_label('Select a file:') ?>
                <?= form_upload( ['name' => 'userfile[]'] ) ?>
            </fieldset>
            <fieldset>
                <?= form_label('Select a file):') ?>
                <?= form_upload( ['name' => 'userfile[]'] ) ?>
            </fieldset>
            <fieldset>
                <?= form_label('Select a file:') ?>
                <?= form_upload( ['name' => 'userfile[]'] ) ?>
            </fieldset>
            
            <?= form_submit('submit', 'Submit', 'accesskey="s"') ?>
        <?= form_close() ?>
But nothing uploads...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB