Change Upload status from PHP

Hello All!

Does anyone knew, SWFuploader have ability to change status (pending, Uploading...) of file from php?

For example - I upload file.
In upload.php file don't pass validation.
How I can change status of it?

if only with using header how/where I can add error codes (in function fileQueueError maybe) If I want make "self made" status?

gyphie's picture

uploadError

One method is to cause PHP to return specific HTTP status codes and then use the uploadError event to capture the status code and handle it.

With Flash Player 9 you should return some text content from your upload script and use uploadSuccess to read the "server data" and handle it.

You cannot return the status during the upload (only once the upload completes or fails).

The actually changing of the HTML display has to be taken care of by JavaScript based on what SWFUpload receives from the server. The contents returned by your upload script do not reach the browser.

Thank You gyphie!!! I try

Thank You gyphie!!!
I try this!!

problems

Helo gyphie, we still cant figure it out.
Its not working.

im sending header by php but nothings changing.
Pleas can you give us a sample php code ??

Thank you
Michal

gyphie's picture

Opens

You have 2 options. Neither way is particularly good. You can return a status of 200 (what normally happens) and some text to indicate an error (from your upload.php). In this case SWFUpload files the uploadSuccess event with the text. You can read this text and react as needed. The issue with this is that SWFUpload thinks the upload was successful and the "Stats" object reflects that. If you aren't using the Stats object then this may not matter to you.

Alternately, you can return some other HTTP Status code (something is the 500 range seems to work). SWFUpload will trigger an uploadError with the HTTP_ERROR and the actual status number. The downside to this is that you can't get any text back from the server, just the number. But you can use different number to mean different things.

To return an different HTTP status code in php use something like this:
header("HTTP/1.1 500 Internal Server Error");

I don't think the text after the 500 has to be anything specific. SWFUpload (Flash Player) won't give it to you anyways. You can use other numbers like 550, 560, etc.

Disclaimer: HTTP Status codes have special meanings for HTTP servers and HTTP clients. Use caution when returning your own status codes as they could have unintended consequences.

ok thanx

here is my solution

function uploadSuccess(file, serverData) {
if(serverData != 'ok'){
this.uploadError(file, serverData, 'ERR');
} else {
try {
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setComplete();
progress.setStatus("Soubor nahán.");
progress.toggleCancel(false);

} catch (ex) {
this.debug(ex);
}
}
}

function uploadError(file, errorCode, message) {
errorCode = parseInt(errorCode);