Ultimate Uploader for PHP v1.3 JavaScript API  

Javascript API General

Ultimate Uploader for PHP provides advanced support of JavaScript API, allowing to command the component from host web page and react to the events occuring during upload process.

Note! The client browser may not support JavaScript or it can be disabled in user browser settings. Therefore it is strongly recommended to consider it at usage JavaScript API placing appropriate messages to the user in tag <noscript>.

The object giving possibility of JavaScript management and event handling is accessed as follows:

var uploadController = document.getElementById("ultimateUploader").Content.JSAPI;

where "ultimateUploader" is an id of the <object> tag representing the Silverlight module on the web page.

It is recommended to get controller object in the function defining in "onLoad" parameter of the <oblect> tag. For example:

<object id="ultimateUploader" data="data:application/x-silverlight-2," ...
    ...
    <param name="onLoad" value="onSilverlightLoaded" />
    ...
</object>

<script type="text/javascript">
    function onSilverlightLoaded() {
        var uploadController = document.getElementById("ultimateUploader").Content.JSAPI;
        ...
    }
</script>

Handling events occuring during upload process

There are 6 events to which you can react in the JavaScript code:

Event name Occurrence condition Event arguments Handler setting example
UploadStarted Start of upload process. no uploadController.UploadStarted = MyStartHandler;
UploadCompleted End of upload process. no uploadController.UploadCompleted = MyCompleteHandler;
UploadCancelled Cancellation of upload process. no uploadController.UploadCancelled = MyCancelHandler;
UploadPaused Pause of upload process. no uploadController.UploadPaused = MyPauseHandler;
UploadFileStarted Start of the specific file upload. string FileName
string FileSize (in bytes)
string ServerResponse
uploadController.UploadFileStarted = MyFileStartHandler;
UploadFileCompleted End of the specific file upload. string FileName
string FileSize (in bytes)
string ServerResponse
uploadController.UploadFileCompleted = MyFileCompleteHandler;

Example handling file upload completion event:

<script type="text/javascript">

    function onSilverlightLoaded() {
        var uploadController = document.getElementById("ultimateUploader").Content.JSAPI;
        uploadController.UploadFileCompleted = MyFileCompleteHandler;
    }

    function MyFileCompleteHandler(sender, args) {
        alert("Complete upload file " + args.FileName + ", size " + args.FileSize + " bytes."
            + "\nServer response: " + args.ServerResponse);
    }
    
</script>

Sending commands to upload control

There are 3 methods which you can use in JavaScript code for send commands to upload control:

Method name Made operation GUI analog Calling example
StartUpload Start or resume upload process. Upload button uploadController.StartUpload();
PauseUpload Pause upload process. Pause button uploadController.PauseUpload();
CancelUpload Cancel upload process. Cancel button uploadController.CancelUpload();

Example using custom start and stop command controls instead of standard buttons:

<object id="ultimateUploader" data="data:application/x-silverlight-2," ...
    ...
    <param name="initParams" value="...HideUploadButton=true,HideCancelButton=true..." />
    ...
</object>

<button type="button" onclick="Start()">Start</button>
<button type="button" onclick="Stop()">Stop</button>
    
<script type="text/javascript">
    function Start() {
        document.getElementById("ultimateUploader").Content.JSAPI.StartUpload();
    }
    function Stop() {
        document.getElementById("ultimateUploader").Content.JSAPI.StopUpload();
    }
</script>