Codeigniter empty $_POST & $_FILES

淺唱寂寞╮ 提交于 2019-12-20 01:17:19

问题


I'm using Plupload to manage file uploads for my site. When I configure Plupload to post to the following test file, the records are shown correctly, however when I post to a CI controller, both $_POST AND $_FILES are empty.

test.php

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

CI does correctly display the $_FILES and $_POST arrays when using a standard HTML form, so any ideas what's causing this?

EDIT here is the plupload config

    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);
    }
}
}

回答1:


Most probable cause for this is bad mod rewrite rules. If you are using any, try disabling them and post your data again.




回答2:


I'm using the input class in conjunction with regular $_POST variables and it has always worked for me. The theory that CI cleans out post variables doesn't add up when he can dump them in regular forms.

Turn off csrf protection and please let us know the results. Use firebug console to read the answer from the server. For a workaround regarding csrf I use https://github.com/EllisLab/CodeIgniter/pull/236

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

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




回答3:


It could be that something in plupload is intercepting $_POST and $_FILES.

In codeigniter its usually better to use the input class to deal with post variables and the file uploading class to deal with file uploads.

I guess that something has emptied the $_POST and $_FILES array for safety, it could be that on including the input and file uploading classes codeigniter itself wipes the $_POST and $_FILES arrays so that you're forced to use their classes. Its always a good idea as codeigniter removes XSS attacks and cleans up variables.



来源:https://stackoverflow.com/questions/9362587/codeigniter-empty-post-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!