How to fire an onError uploadify onError event handler?

I use Uploadify to upload files. The problem is that I have to inform users of any error while processing these files.

Uploadify has an onError , onComplete and onAllComplete event handler, but I don’t know how to fire these events so that users are informed about what is happening.

Do I need to send a JSON string? There is a key here and here and here , but I could not get it to work. Perhaps the forum post is out of date.

Does anyone have any example that works for Uploadify 2.1?

+4
source share
3 answers

It killed me, but I found a way. In the uploadify.php file, I created all my validation. The difference here is that I set HTTP 4xx codes for each type of error.

 if (! in_array($fileParts['extension'], $typesArray)) { header("HTTP/1.1 405"); //any 4XX error will work exit(); } 

This returns the error "405" to uploadify.js.

In the file, I set $ ("# fileInput"). uploadify () I added the onError function.

  'onError' : function(event, ID, fileObj, errorObj) { var r = "<br />ERROR: "; switch(errorObj.info) { case 405: r += "Invalid file type."; break; case 406: r += "Some other error."; break; } setTimeout('$("#fileInput'+ ID + 'span.percentage").html("'+r+'");',111); } 

This makes the uploadify default function exist while it expands.

Hope this help!

+2
source

onError is included in uploadify options:

 $("#fileInput").uploadify({ onError: function(e, q, f, o) { alert("ERROR: " + o.info); } }); 

From Documentation

A function that runs when an error occurs during the boot process. The default event handler attaches the error message to the queue element that returns an error and changes the container of the queue element to red.

Four arguments are sent to the function:

  • event : event object.
  • queueID : the unique identifier of the file that returned the error.
  • fileObj : an object containing information about the selected file.
    • name - file name
    • size - size in bytes of the file
    • createDate - file creation date
    • modifyDate - the last date the file was modified
    • type . The file extension begins with the 'character.
  • errorObj : an object containing error information.
    • type - either "HTTP", "IO", or "Security"
    • information - an error message describing the type of error returned
+4
source
 onError: function (a, b, c, d) { if (d.status == 404) alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>'); else if (d.type === "HTTP") alert('error '+d.type+": "+d.status); else if (d.type ==="File Size") alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB'); else alert('error '+d.type+": "+d.text); }, 
0
source

All Articles