0

While implementing jQuery FileUpload in CodeIgniter everything seems to work, no javascript errors and the files get created in the default folders (chmod'ed 0777), but there are two issues.

1. I can't override the default options on the PHP handler provided by the package. Here is the Controller action I'm using to do so, none of the parameters passed are actually applied, if I dump the options within the UploadHandler I get the default options.

public function fileupload()
{
    if ($this->input->is_ajax_request())
    {
        # load library
        $this->load->library('UploadHandler');

        # upload file
        $upload_handler = new UploadHandler(array(
            'upload_dir' => FCPATH.'upload/realty/'.$this->_user->id.'/',
            'mkdir_mode' => 0777,
            'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
        ));
    }
    else
    {
        redirect('error/page_not_found');
    }
}

2. The script is throwing a error when a file finishes uploading :

SyntaxError: Unexpected token {

Here is the response of an example request :

{"files":[{"name":"nebula-ngc-281.jpg","size":590295,"type":"image\/jpeg","url":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/files\/nebula-ngc-281.jpg","thumbnailUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/files\/thumbnail\/nebula-ngc-281.jpg","deleteUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/?file=nebula-ngc-281.jpg","deleteType":"DELETE"}]}{"files":[{"name":"nebula-ngc-281 (1).jpg","size":0,"type":"image\/jpeg","error":"File upload aborted","deleteUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/?file=nebula-ngc-281%20%281%29.jpg","deleteType":"DELETE"}]}
2
  • Can't say for the CodeIgniter UploadHandler part but the JSON you get is invalid (2 root objects instead of 1) you can check on [JSON Formatter](jsonformatter.curiousconcept.com/] for example Commented May 13, 2015 at 11:55
  • @scollado yes it's true, but there is only one request being made so I don't understand how it's printing out 2 objects in the same request. Commented May 13, 2015 at 12:02

1 Answer 1

1

According to this document Creating Libraries check how we can pass the param in library

so it would be:-

 $options= array(
            'upload_dir' => FCPATH.'upload/realty/'.$this->_user->id.'/',
            'mkdir_mode' => 0777,
            'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
        ));
$this->load->library('UploadHandler',$options);
Sign up to request clarification or add additional context in comments.

1 Comment

I feel stupid now, was focused on the wrong package, that did solve all the problems, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.