CodeIgniter Forums
Upload class problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Upload class problem (/showthread.php?tid=3038)



Upload class problem - El Forum - 09-06-2007

[eluser]emperius[/eluser]
I need to upload few files at the same time.

I made an arrray of input elements

Code:
<table width="700" border="0" cellpadding="5">
    &lt;?
        for($i=0;$i<5;$i++)
        {
            echo "<tr>";
                echo "<td width=\"200\">Фото ".($i+1)."</td>";
                echo "<td width=\"500\">&lt;input type=\"file\" size=\"50%\" name=\"f[$i]\"&gt;</td>";
            echo "</tr>";
        }
    ?&gt;
    <tr>
      <td>&lt;input type="submit"&gt;</td>
      <td>&nbsp;</td>
    </tr>    
  </table>

and in the controller I check if field is not empty and try to upload file.

Code:
if(!empty($_FILES['f']))
{
    $farr = $_FILES['f'];
    for($i=0;$i<count($farr['name']);$i++)
    {
        if($farr['name'][$i] != "")
        {
            $field = "f[$i]";
                
            $config['upload_path'] = realpath('public/object');
            $config['allowed_types'] = 'jpg';
            $this->load->library('upload', $config);
                    
            $this->upload->do_upload($field);
            $resarr = $this->upload->data();
            
            $file = $resarr['file_name'];
                    
            $this->upload->display_errors('<p>', '</p>');
            $this->upload->data();
              }
    }
}

the permission for folder is set 777

and i don't get errors and data about successfull file upload Sad

What I'm doing wrong?


Upload class problem - El Forum - 09-06-2007

[eluser]CI Lee[/eluser]
Hey,

I am very sleepy so bear with me.

Where does your form open and close and do you have
Code:
enctype="multipart/form-data"
in the form tag wherever it lives?

-Lee


Upload class problem - El Forum - 09-06-2007

[eluser]emperius[/eluser]
[quote author="CI Lee" date="1189086951"]Hey,

I am very sleepy so bear with me.

Where does your form open and close and do you have
Code:
enctype="multipart/form-data"
in the form tag wherever it lives?

-Lee[/quote]

of course I have everything. the opening tag, closing and enctype.


Upload class problem - El Forum - 09-10-2007

[eluser]phpMaster[/eluser]
hi!

1. make sure you have 'error_reporting(E_ALL);
2. put in some debugging 'echo' in various places in your code
this way you can track where variables have bad values

Example:
Code:
$field = "f[$i]";
echo $field;
Instead of just echo one value like that,
you can echo TOTAL ARRAY content, if you wish in several stages of your script:

I use this oneliner DUMP VALUES on my Windows PHP setup:
Code:
// $array can be any arrayname or variable
echo '<pre>'. print_r( $array, true ) .'</pre>';

Regards - phpMaster


Upload class problem - El Forum - 09-11-2007

[eluser]ELRafael[/eluser]
[quote author="emperius" date="1189082429"]I need to upload few files at the same time.

I made an arrray of input elements

Code:
<table width="700" border="0" cellpadding="5">
    &lt;?
        for($i=0;$i<5;$i++)
        {
            echo "<tr>";
                echo "<td width=\"200\">Фото ".($i+1)."</td>";
                echo "<td width=\"500\">&lt;input type=\"file\" size=\"50%\" name=\"f[$i]\"&gt;</td>";
            echo "</tr>";
        }
    ?&gt;
    <tr>
      <td>&lt;input type="submit"&gt;</td>
      <td>&nbsp;</td>
    </tr>    
  </table>

and in the controller I check if field is not empty and try to upload file.

Code:
if(!empty($_FILES['f']))
{
    $farr = $_FILES['f'];
    for($i=0;$i<count($farr['name']);$i++)
    {
        if($farr['name'][$i] != "")
        {
            $field = "f[$i]";
                
            $config['upload_path'] = realpath('public/object');
            $config['allowed_types'] = 'jpg';
            $this->load->library('upload', $config);
                    
            $this->upload->do_upload($field);
            $resarr = $this->upload->data();
            
            $file = $resarr['file_name'];
                    
            $this->upload->display_errors('<p>', '</p>');
            $this->upload->data();
              }
    }
}

the permission for folder is set 777

and i don't get errors and data about successfull file upload Sad

What I'm doing wrong?[/quote]

teste if the conditions is true... ah! put a / in the line
Code:
$config['upload_path'] = realpath('public/object');

like this:
Code:
$config['upload_path'] = realpath('public/object/');

and try again!