Welcome Guest, Not a member yet? Register   Sign In
Solved: It does not upload... who does see it? ( CI File Upload Class)
#1

[eluser]Jan_1[/eluser]
I'm trying to upload an image. It works at another modul in my application. Everything is the same (of course not url's). What am I doing wrong? Trying to find out since 6 hours. After using upload-button it stays in the (!$this->upload->do_upload())-area without effect and without errors-printout. Could anyone give me a help? Or may be you have a hint how to find the mistake or a good question to me. Every help wanted. Thank you!!!!

controller suche_in.php:
Code:
function do_upload()
    {
      $config['upload_path'] = '#full-path#/system/application/uploads/inserat/flat';
      $config['allowed_types'] = 'gif|jpg|jpeg|png|JPG|JPEG|PNG|GIF';
      $config['overwrite'] = FALSE;
      $config['max_size'] = 2048;
//        $config['max_size']    = '100';
//        $config['max_width']  = '1024';
//        $config['max_height']  = '768';
      $this->load->library('upload', $config);
      $this->upload->initialize($config);

if ( ! $this->upload->do_upload())    
        {                                  //   <----  I DON'T GET OUT OF HERE  :o(       ########
      $data['heading'] = 'Upload';
      $data['page'] = $this->config->item('FAL_template_dir').'template/Suche/upload_form';
            $error = array('error' => $this->upload->display_errors());
      $this->load->view($this->_container, $data, $error);
     }
else
     {
      $data = array('upload_data' => $this->upload->data());
      print_r($data);
      extract($data);
      extract($upload_data);
      $image = $this->upload->data();                        
      $data['image'] = "#full-path#/system/application/uploads/inserat/flat/".$file_name;
       //     $image = $data['file'];
      $config['image_library'] = 'gd2';
      $config['source_image'] = $image;
      $config['create_thumb'] = TRUE;
      $config['maintain_ratio'] = TRUE;
      $config['width'] = 75;
      $config['new_image'] = "#full-path#/system/application/uploads/inserat/flat/".$image['file_name'];
      $this->load->library('image_lib', $config);
      $this->image_lib->resize();
        $data['heading'] = 'Upload';
      $data = array('upload_data' => $this->upload->data());
      $data['page'] = $this->config->item('FAL_template_dir').'template/Suche/upload_success';
      $this->load->view($this->_container, $data);
     }
}
View upload_form.php:
Code:
<div id=headline>&lt;?=$heading?&gt;</div>
&lt;?php
if (isset($error)){echo $error;}
echo form_open_multipart('suche_in/do_upload');
?&gt;
&lt;input type="file" name="inserat"  /&gt;
&lt;input type="submit" value="hochladen" /&gt;
&lt;/form&gt;
&lt;?=anchor('suche_in/inserateliste', 'back')?&gt;

View upload_success.php
Code:
<div id=headline>Best&auml;tigung:</div>
<h3>Das Foto wurde erfolgreich hochgeladen!</h3>

&lt;?php // echo"<ul>"; foreach($upload_data as $item => $value):?&gt;
&lt;?php // echo"<li>"; echo $item; echo ":";echo $value; echo "</li>"; endforeach; echo"</ul>"; ?&gt;

<p>&lt;?php //echo anchor('upload', 'Weitere Datei hochladen'); ?&gt;</p>

&lt;?=anchor('suche_in/inserateliste', 'back')?&gt;
#2

[eluser]Cro_Crx[/eluser]
Only the second parameter of the view() function takes in data. The third is used for another purpose (sends view to buffer/variable).

So you can't do this:

Code:
$this->load->view($this->_container, $data, $error);

Just pass error as an array element of data. Change this line

Code:
$error = array('error' => $this->upload->display_errors());

to this

Code:
$data['error'] = $this->upload->display_errors();

And this line:

Code:
$this->load->view($this->_container, $data, $error);

to this:

Code:
$this->load->view($this->_container, $data);
#3

[eluser]Jan_1[/eluser]
Thank you!!!
Now I get error-messages.
It' says "You did not select a file to upload."
#4

[eluser]Cro_Crx[/eluser]
Check the do_upload() funciton in the user guide ==> http://ellislab.com/codeigniter/user-gui...ading.html

Says that the file input needs to have the name 'userfile'. You've got your set to 'inserat' in the view. So you can either change it to 'userfile' or pass in your file input name to the do_upload function like this:

Code:
if ( ! $this->upload->do_upload('inserat'))
#5

[eluser]Jan_1[/eluser]
Thank you so much!!!!
That's it.




Theme © iAndrew 2016 - Forum software by © MyBB