Welcome Guest, Not a member yet? Register   Sign In
File upload CSRF Error
#1

[eluser]mstojanov[/eluser]
Hello Guys.

When i was testing my form with only one image the upload form was working very fine.
But now i added 3 input of type files to upload 3 images and i cant this well known error :

The action you have requested is not allowed.

In Firefox once i tried with 3 images and it worked great, the next time when i try again to upload 3 images i get the same error. In the same time while i'm testing to upload images i cant even upload one image while csrf protection is enabled.

I also tried to disable my protection and when i click submit nothing happening.
Here is my config csrf :

Code:
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'oglasi456';
$config['csrf_cookie_name'] = 'cisession';
$config['csrf_expire'] = 7200;

And here is my form :

Code:
<?php $parameters= array('id'=>'mk-font','class'=>'form-horizontal','role'=>'form'); ?>
<?php echo form_open_multipart('upload/do_upload',$parameters); ?>

<label for="image" >Image/s:</label>
&lt;input type="file" id="userfile" name="files[]" &gt;
&lt;input type="file" id="userfile" name="files[]" &gt;
&lt;input type="file" id="userfile" name="files[]" &gt;
&lt;?php echo form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash()); ?&gt;
<button type="submit" name="submit">Insert</button>

&lt;?php echo validation_errors('<div class="alert">','</div>'); ?&gt;
&lt;?php echo form_close(); ?&gt;


How can i really fix this problem with csrf on my upload form. Even when i try to disable csrf the form submit is not working.


Also i want to show you my controller here maybe there is the problem i really dont know :



Code:
class Upload extends CI_Controller {

public function __construct(){
  parent::__construct();
  $this->load->model('oglas_model');
  $this->load->model('user_model');
  $this->load->library('image_lib');
  session_start();
}

function index(){

  if(!isset($_SESSION['logged_in'])){
   redirect(site_url().'/home');
  }
  $this->load->view('nov_oglas',array('error' => ' ' ));

}

function do_upload(){

  if(!isset($_SESSION['logged_in'])){
   redirect(site_url().'/home');
  }

   $this->load->library('upload');

   $this->upload->initialize(array(

                'upload_path' => './uploads',
  'allowed_types' => 'gif|jpg|jpeg|png',
  'max_size' => '4000',
  'encrypt_name' =>TRUE,
  'max_width'  => '4300',
  'max_height'  => '3000',
  'remove_spaces'   => TRUE,
        ));

  $this->load->library('form_validation');

  $this->form_validation->set_rules('address','Address');
  $this->form_validation->set_rules('title','title', 'required');
  $this->form_validation->set_rules('desc','Desc', 'required');
  $this->form_validation->set_rules('price','Price','required|numeric');
    
   if ($this->form_validation->run() !== false) {

if ( $this->upload->do_multi_upload("files")) {

     $data = array('upload_data' => $this->upload->get_multi_upload_data());
   $finfo=$this->upload->get_multi_upload_data();
  
foreach ($finfo as $images ) {

  $filename = $images['file_name'];

  $config['image_library']    = "gd2";      
                $config['source_image']     = "uploads/" .$filename;        
                $config['maintain_ratio']   = TRUE;
                $config['quality'] = "50%";
         $config['width'] = "600";      
                $config['height'] = "600";      

          $this->image_lib->initialize($config);
                $this->image_lib->resize();
                $this->image_lib->clear();  

     }
  $data['uploadInfo'] = $finfo;
  $results=$this->oglas_model->insert_oglas($finfo);
  $this->load->view('upload_success', $data);
  
} else {  
   $error = array('error' => $this->upload->display_errors());
     }
}
  
  $data = array('error' => $this->upload->display_errors());
  $this->load->view('nov_oglas',$data);

       }

}
Waiting for solutions.
Thanks
#2

[eluser]Ckirk[/eluser]
In your config.php try setting a value for both "cookie_prefix" and "cookie_domain".
I've read reports of this problem where that was the solution
#3

[eluser]mstojanov[/eluser]
[quote author="Ckirk" date="1386234395"]In your config.php try setting a value for both "cookie_prefix" and "cookie_domain".
I've read reports of this problem where that was the solution[/quote]

Thanks for your effort.

After i've done this i'm not able to login in my application with my username and password giving me the same error when i try to login :

The action you have requested is not allowed.

Anybody ?




Theme © iAndrew 2016 - Forum software by © MyBB