Skip to content
Advertisement

Codeigniter empty $_POST & $_FILES

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement