Welcome Guest, Not a member yet? Register   Sign In
multiple file html -> do_upload
#1

[eluser]Pana_Ruplahlava[/eluser]
Hi,
i want to use do_upload with this html code:
Code:
<form action="http://192.168.1.100/ruplahlava/a/up" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" multiple name="files[]" />
<input type="text" name="name" value="Název"  />
<input type="text" name="popis" value="Popis"  />
<input type="text" name="heslo" value="Heslo"  />
<input type="submit" name="" value="Vytvoř"  /></form>


...so my $files looks like:
Code:
Array
(
    [files] => Array
        (
            [name] => Array
                (
                    [0] => P1030115 (Kopírovat).JPG
                    [1] => P1030119 (Kopírovat).JPG
                    [2] => P1030120 (Kopírovat).JPG
                    [3] => P1030121 (Kopírovat).JPG
                    [4] => P1030115 (Kopírovat).JPG
                    [5] => P1030119 (Kopírovat).JPG
                    [6] => P1030120 (Kopírovat).JPG
                    [7] => P1030121 (Kopírovat).JPG
                )

            [type] => Array
                (
                    [0] => image/jpeg
                    [1] => image/jpeg
                    [2] => image/jpeg
                    [3] => image/jpeg
                    [4] => image/jpeg
                    [5] => image/jpeg
                    [6] => image/jpeg
                    [7] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => /tmp/phpCIItAb
                    [1] => /tmp/phpAxT6B4
                    [2] => /tmp/phpcPMBEX
                    [3] => /tmp/phpWcj2HQ
                    [4] => /tmp/php46AcMJ
                    [5] => /tmp/phpuP09QC
                    [6] => /tmp/phpzTBZWv
                    [7] => /tmp/phpkwxL3o
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                    [3] => 0
                    [4] => 0
                    [5] => 0
                    [6] => 0
                    [7] => 0
                )

            [size] => Array
                (
                    [0] => 203573
                    [1] => 231124
                    [2] => 245524
                    [3] => 190944
                    [4] => 203573
                    [5] => 231124
                    [6] => 245524
                    [7] => 190944
                )

        )

)

But when i want to use do_upload function in foreach ->


Code:
function _upload() {

        $label = $_POST['name'];
        $path = "./files/$label/";
        if (!is_dir($path)) {
            mkdir($path, 0777);
        }
        $config['upload_path'] = $path;
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = true;
        $this->load->library('upload', $config);
        foreach ($_FILES as $dat =>$value) {
            if (!$this->upload->do_upload($dat)) {
                echo "$$%^&*$@#)*()&*%#&)(*%";
            } else {
                
            }
        }
    }

i get error
Quote:Message: is_uploaded_file() expects parameter 1 to be string, array given


What should i do to make it working? Big Grin Thx for help :)
#2

[eluser]noslen1[/eluser]
The parameter in $this->upload->do_upload() has to be the field name of the upload file input.
Try
Code:
if (!$this->upload->do_upload('files')) {
...
#3

[eluser]Pana_Ruplahlava[/eluser]
nope, still getting
Code:
Message: is_uploaded_file() expects parameter 1 to be string, array given
Undecided
#4

[eluser]Pana_Ruplahlava[/eluser]
Sooooo... After some time i figured it out Big Grin so if you use
Code:
<input type="file" multiple="multiple" name="files[]" />
and you want to upload it with codeigniter, you have to use this rubbish code:
Code:
$fdata = $_FILES['files'];
        $files = array();
        if (is_array($fdata['name'])) {
            for ($i = 0; $i < count($fdata['name']); ++$i) {
                $files[] = array(
                    'files'=>(array(
                    'name' => $fdata['name'][$i],
                    'tmp_name' => $fdata['tmp_name'][$i],
                    'type'=>$fdata['type'][$i],
                    'error'=>$fdata['error'][$i],
                    'size'=>$fdata['size'][$i],
                    
                ))
                        );
            }
        }
        else
            $files[] = $fdata;
        
        foreach ($files as $dat) {
            $_FILES = $dat;
            pre_r($_FILES);
            if (!$this->upload->do_upload('files')) {
                $this->upload->display_errors();
                echo "$$%^&*$@#)*()&*%#&)(*%";
            } else {
                
            }
I had to modify this tutorial to work with CI...
http://verens.com/2009/12/28/multiple-fi...ing-html5/
ofcourse you have to change name of first array as you have in html and the same in do_upload!!!

Hope it helped Smile




Theme © iAndrew 2016 - Forum software by © MyBB