Welcome Guest, Not a member yet? Register   Sign In
cannot upload files to server
#1

[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);
    
   }
  }
#2

[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.
#3

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

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

[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
#6

[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.
#7

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




Theme © iAndrew 2016 - Forum software by © MyBB