Welcome Guest, Not a member yet? Register   Sign In
Problems with CI file upload controller and Flex (FileReference class)
#1

[eluser]log2e[/eluser]
I'm trying to use CI's file uploading class for uploading files from a Flex application. So far I've been using my own PHP script for managing file uploads, but now I'd like to switch to a CI-only PHP solution on the server-side. The HTML-based example from the CI User Guide works fine but I can't figure out what I'm doing wrong when it comes to Flex and CI.

According to Adobe's documentation (FileReference class) the server script that handles the file upload should expect an HTTP POST request with the following elements:

- Content-Type with a value of multipart/form-data.
- Content-Disposition with a name attribute set to "Filedata" and a filename attribute set to the name of the original file.
- The binary contents of the file.

Here's my controller script. It works fine with the HTML-based upload form and views. Please note that I use the $field_name variable with the value "Filedata" for matching the field name with the requirement from Adobe's FileReference documentation.

For using the controller with Flex I comment out the $this->load->view(...) and $this->load->helper(...) lines because they are only needed for the HTML views. I point the URL parameter in my Flex application to "http://www.mydomain.com/index.php/flexupload/do_upload" but it doesn't work.

Code:
<?php

class Flexupload extends Controller {
    
    function Flexupload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {    
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    function do_upload()
    {
        $field_name = "Filedata";
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['overwrite'] = TRUE;
        $config['max_size']    = '1000000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload($field_name))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('upload_success', $data);      
        }
    }    
    
}
?>

Any ideas what I'm doing wrong? Thanks in advance.


Messages In This Thread
Problems with CI file upload controller and Flex (FileReference class) - by El Forum - 05-03-2008, 07:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB