Search code examples
phpjqueryjquery-file-upload

How do I disable output for jQuery File Upload


After upgrading to the latest official release of jquery file upload:

For PHP UploadHandler.php I'm getting output similar to:

{
    "files": [{
        "name": "1367159262-79",
        "size": 0,
        "type": "multipart\/form-data; boundary=---------------------------7d115d2a20060c",
        "error": "abort",
        "delete_url": "http:\/\/my-site.com\/photos\/?file=1367159262-79",
        "delete_type": "DELETE",
        "id": null
    }]
}

Our apps are choking on this output.

If I set the print_response to false for the post method like so I no longer see the above output which works great on the app side. Unfortunately when I do this I now see: Empty file upload result after uploading a file via the web.

return $this->generate_response(
       array($this->options['param_name'] => $files),
       false
);

Any idea how I can eliminate this JSON output and not get the Empty file upload result error?


Solution

  • I ended up adding an argument to the cosntructor for UploadHandler and setting it to false for the apps. There might be a better way but it solves the issues for me:

    function __construct($options = null, $initialize = true, $error_messages = null, $print_response = true) {
        ...
    }
    

    For the apps I did this:

    $options = null;
    $initialize = true;
    $error_messages = null;
    $print_response = false;
    
    $upload_handler = new UploadHandler($options, $initialize, $error_messages, $print_response);