CodeIgniter Forums
cannot upload files to server - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: cannot upload files to server (/showthread.php?tid=60420)



cannot upload files to server - El Forum - 03-23-2014

[eluser]vimeo[/eluser]
I have a basic knowledge on codeigniter.
I want upload a file and save it .I used the following code but it's not working properly.
can anyone please explain how to do it properly?

controller
Code:
public function doUpload()
  {
   $config['upload_path']='./images/';
   $config['allowed_types']='gif|png|jpg|jepg'; // images types
   $config['max_size'] = '1000';
   $config['max_width'] = '800';
   $config['max_height'] = '600';
  
   $this->load->library('upload',$config); //using inbuilt libraries
   $this->load->library('image_lib');
  
  
   if(!$this->upload->do_upload()){
    $data['message'] = $this->upload->display_errors();
    $this->load->view('error');
    
   }
   else if($this->upload->do_upload()){
    $data =  array('upload_data' => $this->upload->data());
    echo 'upload success';
    $this->load->view('success',$data);
    
   }
  }



cannot upload files to server - El Forum - 03-23-2014

[eluser]vimeo[/eluser]
I think the problem is with the path.But i can't figure it out.
I've been going through codes for days.
any help would be appreciated.



cannot upload files to server - El Forum - 03-23-2014

[eluser]jonez[/eluser]
What error message do you get?


cannot upload files to server - El Forum - 03-23-2014

[eluser]Tpojka[/eluser]
(Not just) as beginner you should use basic example provided in user guide. Works perfectly.


cannot upload files to server - El Forum - 03-24-2014

[eluser]vimeo[/eluser]
[quote author="jonez" date="1395577851"]What error message do you get?[/quote]

Code:
success page
<?php
      foreach ($upload_data as $item=>$value): ?>
      
      <?php endforeach; ?>
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: upload_data

Filename: views/success.php

Line Number: 14

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/success.php

Line Number: 14


cannot upload files to server - El Forum - 03-24-2014

[eluser]Tpojka[/eluser]
So, you are trying to upload more than one file.
For that achievment you should use some extensions to CI default upload library.
Try with this one.


cannot upload files to server - El Forum - 05-15-2014

[eluser]vimeo[/eluser]
solved it.
However I had to change 'upload path ' to $config['upload_path']='images/';
Thanks everyone for suggestions.