Codeigniter is empty $ _POST & $ _FILES

I use Plupload to control file uploads for my site. When I configure Plupload to publish to the next test file, the entries are displayed correctly, however when sending to the CI controller the values ​​$ _POST and $ _FILES are empty.

test.php

<?php print_r($_FILES); print_r($_POST); ?> 

CI correctly displays $ _FILES and $ _POST arrays when using a standard HTML form, so any ideas that cause this?

EDIT here is the plupload configuration

  var uploader = new plupload.Uploader({ runtimes : 'html5,html4,flash,silverlight,browserplus', browse_button : 'pickfiles', container : 'container', max_file_size : '15mb', url : '/test.php', //url : '/upload/do_upload/', flash_swf_url : '/js/plupload/plupload.flash.swf', silverlight_xap_url : '/js/plupload/plupload.silverlight.xap', filters : [ {title : "Documents", extensions : "pdf,doc,docx,rtf,txt"} ], multipart_params : { job : -2 } }); 

and here is the controller

 class Upload extends CI_Controller { function __construct() { parent::__construct(); } function index() { $this->load->view('upload_form', array('error' => ' ' )); } function do_upload() { print_r($_POST); print_r($_FILES); $config['upload_path'] = 'incoming/'; $config['allowed_types'] = 'pdf|doc|docx|rtf|txt'; $config['max_size'] = '900'; $this->load->library('upload'); $this->upload->initialize($config); // MUST CALL ELSE config not loaded if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $error); } else { $data = array('upload_data' => $this->upload->data()); $this->load->model('translation_model'); $this->translation_model->add_orig($job, $filePath); $this->load->view('upload_success', $data); } } } 
+4
source share
3 answers

The most likely reason for this is incorrect rewriting rules. If you use them, try disabling them and republish your data again.

+5
source

I use the input class in combination with the $ _POST regular variables, and it always worked for me. The theory that CI cleans up post variables doesn't add up when it can dump them in regular forms.

Disable csrf protection and let us know the results. Use the firebug console to read the response from the server. To solve the csrf problem, I use https://github.com/EllisLab/CodeIgniter/pull/236

CodeIgniter also has problems with file types. http://codeigniter.com/forums/viewthread/113029

I have working libraries for both, if you want them to just send me a message.

+1
source

Maybe something in plupload intercepts $ _POST and $ _FILES.

In codeigniter, it is usually best to use an input class to handle post variables and a file upload class to deal with file uploads .

I suppose that something freed up the $ _POST and $ _FILES array for security, it is possible that when you enable the input and file loading classes, codeigniter itself erases the $ _POST and $ _FILES arrays, so you have to use their classes. Its always a good idea, as codeigniter removes XSS attacks and clears variables.

0
source

Source: https://habr.com/ru/post/1397432/


All Articles