JavaScript DHTML/YUI Library/Uploader

Материал из Web эксперт
Перейти к: навигация, поиск

Advanced Uploader Example With Additional POST Variables and Server Data Return

   <source lang="html4strict">

<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Advanced Uploader Example With Additional POST Variables and Server Data Return</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/uploader/uploader.js"></script>

</head> <body class=" yui-skin-sam">

Advanced Uploader Example With Additional POST Variables and Server Data Return

This example demonstrates how the Uploader can be rendered as a transparent layer on top of your own UI, and how custom variables can be added to the upload"s POST request. In this example, the server-side script also echoes the POST variables accompanying the upload; we retrieve the data returned by the server and display it to the user.

Note: The YUI Uploader Control requires Flash Player 9.0.45 or higher. The latest version of Flash Player is available at the <a href="http://www.adobe.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.

Note: The YUI Uploader Control requires the uploader.swf Flash file that is distributed as part of the YUI package, in the uploader/assets folder. Copy the uploader.swf to your server and set the YAHOO.Uploader.SWFURL variable to its full path.

Note: This example uses a server-side script to accept file uploads. The script used does not open or store the file data sent to it. It also does not store the accompanying POST variables, but it does echo them in the response relayed back to the sender of the request. When trying out the example, do not send any sensitive or private data. Do not exceed file size of 10 MB. </div> <style>

  1. selectFilesLink a, #uploadFilesLink a, #clearFilesLink a {
color: #0000CC; background-color: #FFFFFF; }
  1. selectFilesLink a:visited, #uploadFilesLink a:visited, #clearFilesLink a:visited {
color: #0000CC; background-color: #FFFFFF; }
  1. uploadFilesLink a:hover, #clearFilesLink a:hover {
color: #FFFFFF; background-color: #000000; } </style>
   Set custom values for a couple POST vars:
var1: <input type="text" id="var1Value" value="var1 default value" />
var2: <input type="text" id="var2Value" value="var2 default value" />


   Progress: <input type="text" cols="50" id="progressReport" value="" readonly />

   Data returned by the server:
<textarea id="serverData" rows="5" cols="50"></textarea>

<script type="text/javascript"> YAHOO.util.Event.onDOMReady(function () { var uiLayer = YAHOO.util.Dom.getRegion("selectLink"); var overlay = YAHOO.util.Dom.get("uploaderOverlay"); YAHOO.util.Dom.setStyle(overlay, "width", uiLayer.right-uiLayer.left + "px"); YAHOO.util.Dom.setStyle(overlay, "height", uiLayer.bottom-uiLayer.top + "px"); });

 // Custom URL for the uploader swf file (same folder).
 YAHOO.widget.Uploader.SWFURL = "yui_2.7.0b-assets/uploader-assets/uploader.swf";
   // Instantiate the uploader and write it to its placeholder div.
 var uploader = new YAHOO.widget.Uploader( "uploaderOverlay" );
 
 // Add event listeners to various events on the uploader.
 // Methods on the uploader should only be called once the 
 // contentReady event has fired.
 
 uploader.addListener("contentReady", handleContentReady);
 uploader.addListener("fileSelect", onFileSelect)
 uploader.addListener("uploadStart", onUploadStart);
 uploader.addListener("uploadProgress", onUploadProgress);
 uploader.addListener("uploadCancel", onUploadCancel);
 uploader.addListener("uploadComplete", onUploadComplete);
 uploader.addListener("uploadCompleteData", onUploadResponse);
 uploader.addListener("uploadError", onUploadError);
   uploader.addListener("rollOver", handleRollOver);
   uploader.addListener("rollOut", handleRollOut);
   uploader.addListener("click", handleClick);
     
   // Variable for holding the selected file id.
 var fileID;
 
 // When the mouse rolls over the uploader, this function
 // is called in response to the rollOver event.
 // It changes the appearance of the UI element below the Flash overlay.
 function handleRollOver () {
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#FFFFFF");
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#000000");
 }
 
 // On rollOut event, this function is called, which changes the appearance of the
 // UI element below the Flash layer back to its original state.
 function handleRollOut () {
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#0000CC");
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#FFFFFF");
 }
 
 // When the Flash layer is clicked, the "Browse" dialog is invoked.
 // The click event handler allows you to do something else if you need to.
 function handleClick () {
 }
 
 // When contentReady event is fired, you can call methods on the uploader.
 function handleContentReady () {
     // Allows the uploader to send log messages to trace, as well as to YAHOO.log
   uploader.setAllowLogging(true);
   
   // Disallows multiple file selection in "Browse" dialog.
   uploader.setAllowMultipleFiles(false);
   
   // New set of file filters.
   var ff = new Array({description:"Images", extensions:"*.jpg;*.png;*.gif"},
                      {description:"Videos", extensions:"*.avi;*.mov;*.mpg"});
                      
   // Apply new set of file filters to the uploader.
   uploader.setFileFilters(ff);
 }
 // Actually uploads the files. Since we are only allowing one file
 // to be selected, we use the upload function, in conjunction with the id 
 // of the selected file (returned by the fileSelect event). We are also including
 // the text of the variables specified by the user in the input UI.
 function upload() {
 if (fileID != null) {
   uploader.upload(fileID, "http://www.yswfblog.ru/upload/upload.php", 
                   "POST", 
                   {var1:document.getElementById("var1Value").value,
            var2:document.getElementById("var2Value").value});
 }  
 }
 
 // Fired when the user selects files in the "Browse" dialog
 // and clicks "Ok". Here, we set the value of the progress
 // report textfield to reflect the fact that a file has been
 // selected.
 
 function onFileSelect(event) {
   for (var file in event.fileList) {
       if(YAHOO.lang.hasOwnProperty(event.fileList, file)) {
       fileID = event.fileList[file].id;
     }
   }
   
   this.progressReport = document.getElementById("progressReport");
   this.progressReport.value = "Selected " + event.fileList[fileID].name;
 }
   // When the upload starts, we inform the user about it via
 // the progress report textfield. 
 function onUploadStart(event) {
   this.progressReport.value = "Starting upload...";
 }
 
 // As upload progresses, we report back to the user via the
 // progress report textfield.
 function onUploadProgress(event) {
   prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
   this.progressReport.value = prog + "% uploaded...";
 }
 
 // Report back to the user that the upload has completed.
 function onUploadComplete(event) {
   this.progressReport.value = "Upload complete.";
 }
 
 // Report back to the user if there has been an error.
 function onUploadError(event) {
   this.progressReport.value = "Upload error.";
 }
 
 // Do something if an upload is canceled.
 function onUploadCancel(event) {
 }
 
 // When the data is received back from the server, display it to the user
 // in the server data text area.
 function onUploadResponse(event) {
   this.serverData = document.getElementById("serverData");
   this.serverData.value = event.data;
 }

</script>


</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Advanced Uploader Example With Cookie Submission as a POST variable

   <source lang="html4strict">

<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Advanced Uploader Example With Cookie Submission as a POST variable</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/uploader/uploader.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/cookie/cookie-min.js"></script>

</head> <body class=" yui-skin-sam">

Advanced Uploader Example With Cookie Submission as a POST variable

 <p>One of the major limitations of the Flash-based uploader is that it cannot use browser cookies to authenticate file uploads. In this example, we provide sample code that demonstrates how to attach the page cookie as a variable in the body of the upload POST request, rather than in the header. The code will generate a cookie with a username and the last uploaded file name, and send the value along with the file that needs to be uploaded. We also provide a sample backend script that accepts the file upload and echoes the POST variables accompanying the upload (thus ascertaining that the cookie data was received by the server).  We show how we can retrieve the data returned by the server and display it to the user.</p>

<p>Note: This is a static example, which means that you will not be able to try it out on our server. You will need to set up the code on your own server in order to run it.</p> <p>Note: The YUI Uploader Control requires Flash Player 9.0.45 or higher. The latest version of Flash Player is available at the <a href="http://www.adobe.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p> <p>Note: The YUI Uploader Control requires the uploader.swf Flash file that is distributed as part of the YUI package, in the uploader/assets folder. Copy the uploader.swf to your server and set the YAHOO.Uploader.SWFURL variable to its full path.</p> <p>Note: this example is static, which means that it will not work properly on this page. To try it, you will need to download its source code and set it up on your own server. To do so, click "View example in new window", and save the source of that page.</p>

<style>

  1. selectFilesLink a, #uploadFilesLink a, #clearFilesLink a {
 color: #0000CC;
 background-color: #FFFFFF;

}

  1. selectFilesLink a:visited, #uploadFilesLink a:visited, #clearFilesLink a:visited {
 color: #0000CC;
 background-color: #FFFFFF;

}

  1. uploadFilesLink a:hover, #clearFilesLink a:hover {
 color: #FFFFFF;
 background-color: #000000;

} </style>



   Progress: <input type="text" cols="50" id="progressReport" value="" readonly />

   Data returned by the server:
<textarea id="serverData" rows="15" cols="50" readonly="yes"> </textarea>

<script type="text/javascript">

  // init messageContainer.
 function init() { 
   var curCookie = YAHOO.util.Cookie.get("myCookie");
   var messageContainer = document.getElementById("messageContainer");
   var newHtml;
   var currentUser = YAHOO.util.Cookie.getSub("myCookie","currentUser");
   var lastUploadedFile = YAHOO.util.Cookie.getSub("myCookie","lastUploadedFile");
 
   if(curCookie == null || currentUser == null) {
     // If there is no existing cookie or username, this wiil show the text input and a button to add user name to the cookie.
     YAHOO.util.Cookie.set("myCookie", document.cookie);
     newHtml = "Hi, there. Add your name in the box below.
"; newHtml +="<input type="text" id="userInput" value="Anonymous" /><input type="button" value="Set User" id="btnAdd" />"; }else{ // If there is an existing cookie, this wiil show welcome message with an option of removing the username and file name from the cookie. newHtml = currentUser+", welcome back!
"; if(lastUploadedFile) { newHtml += "Your last uploaded file was "+lastUploadedFile+"
"; } newHtml +="<input type="button" value="Remove User" id="btnRemove" />"; }; messageContainer.innerHTML = newHtml; // reset progressReport and serverData feild. this.serverData = document.getElementById("serverData"); this.serverData.value = ""; this.progressReport = document.getElementById("progressReport"); this.progressReport.value =""; }; // when DOM is ready, call init(). YAHOO.util.Event.onDOMReady(init); // Button Event: "Set User" button clicked. Adds the username to the cookie. YAHOO.util.Event.on("btnAdd", "click", function(){ var newUser = document.getElementById("userInput").value; YAHOO.util.Cookie.setSub("myCookie","currentUser",newUser); var newHtml = "Hi, "+ newUser +"!"; var messageContainer = document.getElementById("messageContainer"); messageContainer.innerHTML = newHtml; }); // Button Event: "Remove User" button clicked. Removes username and last Uploaded File name from the cookie. YAHOO.util.Event.on("btnRemove", "click", function(){ YAHOO.util.Cookie.removeSub("myCookie","currentUser"); YAHOO.util.Cookie.removeSub("myCookie","lastUploadedFile"); init(); }); YAHOO.util.Event.onDOMReady(function () { var uiLayer = YAHOO.util.Dom.getRegion("selectLink"); var overlay = YAHOO.util.Dom.get("uploaderOverlay"); YAHOO.util.Dom.setStyle(overlay, "width", uiLayer.right-uiLayer.left + "px"); YAHOO.util.Dom.setStyle(overlay, "height", uiLayer.bottom-uiLayer.top + "px"); }); // Custom URL for the uploader swf file (same folder). YAHOO.widget.Uploader.SWFURL = "yui_2.7.0b-assets/uploader-assets/uploader.swf"; // Instantiate the uploader and write it to its placeholder div. var uploader = new YAHOO.widget.Uploader( "uploaderOverlay" ); // Add event listeners to various events on the uploader. // Methods on the uploader should only be called once the // contentReady event has fired. uploader.addListener("contentReady", handleContentReady); uploader.addListener("fileSelect", onFileSelect) uploader.addListener("uploadStart", onUploadStart); uploader.addListener("uploadProgress", onUploadProgress); uploader.addListener("uploadCancel", onUploadCancel); uploader.addListener("uploadComplete", onUploadComplete); uploader.addListener("uploadCompleteData", onUploadResponse); uploader.addListener("uploadError", onUploadError); uploader.addListener("rollOver", handleRollOver); uploader.addListener("rollOut", handleRollOut); uploader.addListener("click", handleClick); // Variable for holding the selected file id. var fileID; // Variable for holding the selected file name. var fileName; // When the mouse rolls over the uploader, this function // is called in response to the rollOver event. // It changes the appearance of the UI element below the Flash overlay. function handleRollOver () { YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#FFFFFF"); YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#000000"); } // On rollOut event, this function is called, which changes the appearance of the // UI element below the Flash layer back to its original state. function handleRollOut () { YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#0000CC"); YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#FFFFFF"); } // When the Flash layer is clicked, the "Browse" dialog is invoked. // The click event handler allows you to do something else if you need to. function handleClick () { } // When contentReady event is fired, you can call methods on the uploader. function handleContentReady () { // Allows the uploader to send log messages to trace, as well as to YAHOO.log uploader.setAllowLogging(true); // Disallows multiple file selection in "Browse" dialog. uploader.setAllowMultipleFiles(false); // New set of file filters. var ff = new Array({description:"Images", extensions:"*.jpg;*.png;*.gif"}, {description:"Videos", extensions:"*.avi;*.mov;*.mpg"}); // Apply new set of file filters to the uploader. uploader.setFileFilters(ff); } // Actually uploads the files. Since we are only allowing one file // to be selected, we use the upload function, in conjunction with the id // of the selected file (returned by the fileSelect event). We are also including // the cookie as a variable. function upload() { if (fileID != null) { var docCookie = YAHOO.util.Cookie.get("myCookie"); uploader.upload(fileID, "YOUR_DOMAIN_SAME_AS_PAGE_DOMAIN_HERE", "POST", {cookieVar:docCookie }); } } // Fired when the user selects files in the "Browse" dialog // and clicks "Ok". Here, we set the value of the progress // report textfield to reflect the fact that a file has been // selected. function onFileSelect(event) { for (var file in event.fileList) { if(YAHOO.lang.hasOwnProperty(event.fileList, file)) { fileID = event.fileList[file].id; } } this.progressReport = document.getElementById("progressReport"); fileName = event.fileList[fileID].name; this.progressReport.value = "Selected " + fileName }
   // When the upload starts, we inform the user about it via
 // the progress report textfield. 
 function onUploadStart(event) {
   this.progressReport.value = "Starting upload...";
 }
 
 // As upload progresses, we report back to the user via the
 // progress report textfield.
 function onUploadProgress(event) {
   prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
   this.progressReport.value = prog + "% uploaded...";
 }
 
 // Report back to the user that the upload has completed.
 function onUploadComplete(event) {
   YAHOO.util.Cookie.setSub("myCookie","lastUploadedFile",fileName);
   this.progressReport.value = "Upload complete.";
 }
 
 // Report back to the user if there has been an error.
 function onUploadError(event) {
   this.progressReport.value = "Upload error.";
 }
 
 // Do something if an upload is canceled.
 function onUploadCancel(event) {
 }
 
 // When the data is received back from the server, display it to the user
 // in the server data text area.
 function onUploadResponse(event) {
   
   this.serverData = document.getElementById("serverData");
   this.serverData.value = event.data;
   
 }

</script>

</body>

 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Advanced Uploader Example With Transparent UI and Automatic Queue Management

   <source lang="html4strict">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Advanced Uploader Example With Transparent UI and Automatic Queue Management</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/datatable/assets/skins/sam/datatable.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/uploader/uploader.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datasource/datasource-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/datatable/datatable-min.js"></script>

</head> <body class=" yui-skin-sam">

Advanced Uploader Example With Transparent UI and Automatic Queue Management

 <p>This example demonstrates how the Uploader can be rendered as a transparent layer on top of your own UI, and how the upload queue of multiple files can be managed automatically.</p>

<p>Note: The YUI Uploader Control requires Flash Player 9.0.45 or higher. The latest version of Flash Player is available at the <a href="http://www.adobe.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p> <p>Note: The YUI Uploader Control requires the uploader.swf Flash file that is distributed as part of the YUI package, in the uploader/assets folder. Copy the uploader.swf to your server and set the YAHOO.Uploader.SWFURL variable to its full path.</p> <p>Note: This example uses a server-side script to accept file uploads. The script used does not open or store any data sent to it. Nonetheless, when trying out the example, do not send any sensitive or private data. Do not exceed file size of 10 MB.

<style>

  1. selectFilesLink a, #uploadFilesLink a, #clearFilesLink a {
 color: #0000CC;
 background-color: #FFFFFF;

}

  1. selectFilesLink a:visited, #uploadFilesLink a:visited, #clearFilesLink a:visited {
 color: #0000CC;
 background-color: #FFFFFF;

}

  1. uploadFilesLink a:hover, #clearFilesLink a:hover {
 color: #FFFFFF;
 background-color: #000000;

} </style>

Number of simultaneous uploads:
 <select id="simulUploads">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
 </select>

<script type="text/javascript"> YAHOO.util.Event.onDOMReady(function () { var uiLayer = YAHOO.util.Dom.getRegion("selectLink"); var overlay = YAHOO.util.Dom.get("uploaderOverlay"); YAHOO.util.Dom.setStyle(overlay, "width", uiLayer.right-uiLayer.left + "px"); YAHOO.util.Dom.setStyle(overlay, "height", uiLayer.bottom-uiLayer.top + "px"); });

 // Custom URL for the uploader swf file (same folder).
 YAHOO.widget.Uploader.SWFURL = "yui_2.7.0b-assets/uploader-assets/uploader.swf";
   // Instantiate the uploader and write it to its placeholder div.
 var uploader = new YAHOO.widget.Uploader( "uploaderOverlay" );
 
 // Add event listeners to various events on the uploader.
 // Methods on the uploader should only be called once the 
 // contentReady event has fired.
 
 uploader.addListener("contentReady", handleContentReady);
 uploader.addListener("fileSelect", onFileSelect)
 uploader.addListener("uploadStart", onUploadStart);
 uploader.addListener("uploadProgress", onUploadProgress);
 uploader.addListener("uploadCancel", onUploadCancel);
 uploader.addListener("uploadComplete", onUploadComplete);
 uploader.addListener("uploadCompleteData", onUploadResponse);
 uploader.addListener("uploadError", onUploadError);
   uploader.addListener("rollOver", handleRollOver);
   uploader.addListener("rollOut", handleRollOut);
   uploader.addListener("click", handleClick);
     
   // Variable for holding the filelist.
 var fileList;
 
 // When the mouse rolls over the uploader, this function
 // is called in response to the rollOver event.
 // It changes the appearance of the UI element below the Flash overlay.
 function handleRollOver () {
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#FFFFFF");
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#000000");
 }
 
 // On rollOut event, this function is called, which changes the appearance of the
 // UI element below the Flash layer back to its original state.
 function handleRollOut () {
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "color", "#0000CC");
   YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get("selectLink"), "background-color", "#FFFFFF");
 }
 
 // When the Flash layer is clicked, the "Browse" dialog is invoked.
 // The click event handler allows you to do something else if you need to.
 function handleClick () {
 }
 
 // When contentReady event is fired, you can call methods on the uploader.
 function handleContentReady () {
     // Allows the uploader to send log messages to trace, as well as to YAHOO.log
   uploader.setAllowLogging(true);
   
   // Allows multiple file selection in "Browse" dialog.
   uploader.setAllowMultipleFiles(true);
   
   // New set of file filters.
   var ff = new Array({description:"Images", extensions:"*.jpg;*.png;*.gif"},
                      {description:"Videos", extensions:"*.avi;*.mov;*.mpg"});
                      
   // Apply new set of file filters to the uploader.
   uploader.setFileFilters(ff);
 }
 // Actually uploads the files. In this case,
 // uploadAll() is used for automated queueing and upload 
 // of all files on the list.
 // You can manage the queue on your own and use "upload" instead,
 // if you need to modify the properties of the request for each
 // individual file.
 function upload() {
 if (fileList != null) {
   uploader.setSimUploadLimit(parseInt(document.getElementById("simulUploads").value));
   uploader.uploadAll("http://www.yswfblog.ru/upload/upload_simple.php", "POST", null, "Filedata");
 }  
 }
 
 // Fired when the user selects files in the "Browse" dialog
 // and clicks "Ok".
 function onFileSelect(event) {
   if(YAHOO.lang.hasOwnProperty(event, fileList) && event.fileList != null) {
     fileList = event.fileList;
     createDataTable(fileList);
   }
 }
 function createDataTable(entries) {
   rowCounter = 0;
   this.fileIdHash = {};
   this.dataArr = [];
   for(var i in entries) {
      var entry = entries[i];
entry["progress"] = "
";
      dataArr.unshift(entry);
   }
 
   for (var j = 0; j < dataArr.length; j++) {
     this.fileIdHash[dataArr[j].id] = j;
   }
 
     var myColumnDefs = [
         {key:"name", label: "File Name", sortable:false},
        {key:"size", label: "Size", sortable:false},
        {key:"progress", label: "Upload progress", sortable:false}
     ];
   this.myDataSource = new YAHOO.util.DataSource(dataArr);
   this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
     this.myDataSource.responseSchema = {
         fields: ["id","name","created","modified","type", "size", "progress"]
     };
   this.singleSelectDataTable = new YAHOO.widget.DataTable("dataTableContainer",
            myColumnDefs, this.myDataSource, {
                caption:"Files To Upload",
                selectionMode:"single"
            });
 }
   // Do something on each file"s upload start.
 function onUploadStart(event) {
 
 }
 
 // Do something on each file"s upload progress event.
 function onUploadProgress(event) {
   rowNum = fileIdHash[event["id"]];
   prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
progbar = "
";
   singleSelectDataTable.updateRow(rowNum, {name: dataArr[rowNum]["name"], size: dataArr[rowNum]["size"], progress: progbar});  
 }
 
 // Do something when each file"s upload is complete.
 function onUploadComplete(event) {
   rowNum = fileIdHash[event["id"]];
   prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
progbar = "
";
   singleSelectDataTable.updateRow(rowNum, {name: dataArr[rowNum]["name"], size: dataArr[rowNum]["size"], progress: progbar});
 }
 
 // Do something if a file upload throws an error.
 // (When uploadAll() is used, the Uploader will
 // attempt to continue uploading.
 function onUploadError(event) {
 }
 
 // Do something if an upload is cancelled.
 function onUploadCancel(event) {
 }
 
 // Do something when data is received back from the server.
 function onUploadResponse(event) {
 }

</script>


</body> </html>


 </source>
   
  

<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>


Simple Uploader Example With Button UI

   <source lang="html4strict">


<head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Simple Uploader Example With Button UI</title> <style type="text/css"> /*margin and padding on body element

 can introduce errors in determining
 element position and are not recommended;
 we turn them off as a foundation for YUI
 CSS treatments. */

body {

 margin:0;
 padding:0;

} </style> <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts-min.css" /> <script type="text/javascript" src="yui_2.7.0b-lib/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/element/element-min.js"></script> <script type="text/javascript" src="yui_2.7.0b-lib/uploader/uploader.js"></script>

</head> <body class=" yui-skin-sam">

Simple Uploader Example With Button UI

 <p>This example is a demonstration of the <a href="../../uploader/">YUI Uploader Control</a>"s features.</p>

<p>Note: The YUI Uploader Control requires Flash Player 9.0.45 or higher. The latest version of Flash Player is available at the <a href="http://www.adobe.ru/go/getflashplayer">Adobe Flash Player Download Center</a>.</p> <p>Note: The YUI Uploader Control requires the uploader.swf Flash file that is distributed as part of the YUI package, in the uploader/assets folder. Copy the uploader.swf to your server and set the YAHOO.Uploader.SWFURL variable to its full path.</p> <p>Note: This example uses a server-side script to accept file uploads. The script used does not open or store any data sent to it. Nonetheless, when trying out the example, do not send any sensitive or private data. Do not exceed file size of 10 MB.

<style type="text/css">

 .uploadButton a, .clearButton a {
   display:block;
   width:100px;
   height:40px;
   text-decoration: none;
   margin-left:5px;
 }
 
 .uploadButton a {
   background: url("yui_2.7.0b-assets/uploader-assets/uploadFileButton.png") 0 0 no-repeat;
 }
 
 .clearButton a {
   background: url("yui_2.7.0b-assets/uploader-assets/clearListButton.png") 0 0 no-repeat;
 }
 
   .uploadButton a:visited, .clearButton a:visited {
   background-position: 0 0;
 }
 
   .uploadButton a:hover, .clearButton a:hover {  
   background-position: 0 -40px;
 }
 
   .uploadButton a:active, .clearButton a:active {
   background-position: 0 -80px;
 }

</style>

<a class="rolloverButton" href="#" onClick="upload(); return false;"></a>
<a class="rolloverButton" href="#" onClick="handleClearFiles(); return false;"></a>

<script type="text/javascript">

   // Instantiate the uploader and write it to its placeholder div.
 
 YAHOO.widget.Uploader.SWFURL = "yui_2.7.0b-assets/uploader-assets/uploader.swf";
 
 var uploader = new YAHOO.widget.Uploader( "uploaderUI", "yui_2.7.0b-assets/uploader-assets/selectFileButton.png" );
 
 // Add event listeners to various events on the uploader.
 // Methods on the uploader should only be called once the 
 // contentReady event has fired.
 
 uploader.addListener("contentReady", handleContentReady);
 uploader.addListener("fileSelect",onFileSelect)
 uploader.addListener("uploadStart",onUploadStart);
 uploader.addListener("uploadProgress",onUploadProgress);
 uploader.addListener("uploadCancel",onUploadCancel);
 uploader.addListener("uploadComplete",onUploadComplete);
 uploader.addListener("uploadCompleteData",onUploadResponse);
 uploader.addListener("uploadError", onUploadError);
     
   // Variable for holding the selected file ID.
 var fileID;
 
 function handleClearFiles() {
 uploader.clearFileList();
 uploader.enable();
 fileID = null;
 
 var filename = document.getElementById("fileName");
 filename.innerHTML = "";
 
 var progressbar = document.getElementById("progressBar");
 progressbar.innerHTML = "";
 }
   
 // When contentReady event is fired, you can call methods on the uploader.
 function handleContentReady () {
     // Allows the uploader to send log messages to trace, as well as to YAHOO.log
   uploader.setAllowLogging(true);
   
   // Restrict selection to a single file (that"s what it is by default,
   // just demonstrating how).
   uploader.setAllowMultipleFiles(false);
   
   // New set of file filters.
   var ff = new Array({description:"Images", extensions:"*.jpg;*.png;*.gif"},
                      {description:"Videos", extensions:"*.avi;*.mov;*.mpg"});
                      
   // Apply new set of file filters to the uploader.
   uploader.setFileFilters(ff);
 }
 // Initiate the file upload. Since there"s only one file, 
 // we can use either upload() or uploadAll() call. fileList 
 // needs to have been populated by the user.
 function upload() {
 if (fileID != null) {
   uploader.upload(fileID, "http://www.yswfblog.ru/upload/upload_simple.php");
   fileID = null;
 }
 }
 
 // Fired when the user selects files in the "Browse" dialog
 // and clicks "Ok".
 function onFileSelect(event) {
   for (var item in event.fileList) {
       if(YAHOO.lang.hasOwnProperty(event.fileList, item)) {
       YAHOO.log(event.fileList[item].id);
       fileID = event.fileList[item].id;
     }
   }
   uploader.disable();
   
   var filename = document.getElementById("fileName");
   filename.innerHTML = event.fileList[fileID].name;
   
   var progressbar = document.getElementById("progressBar");
   progressbar.innerHTML = "";
 }
   // Do something on each file"s upload start.
 function onUploadStart(event) {
 
 }
 
 // Do something on each file"s upload progress event.
 function onUploadProgress(event) {
   prog = Math.round(300*(event["bytesLoaded"]/event["bytesTotal"]));
     progbar = "<div style=\"background-color: #f00; height: 5px; width: " + prog + "px\"/>";
   var progressbar = document.getElementById("progressBar");
   progressbar.innerHTML = progbar;
 }
 
 // Do something when each file"s upload is complete.
 function onUploadComplete(event) {
   uploader.clearFileList();
   uploader.enable();
   
   progbar = "<div style=\"background-color: #f00; height: 5px; width: 300px\"/>";
   var progressbar = document.getElementById("progressBar");
   progressbar.innerHTML = progbar;
 }
 
 // Do something if a file upload throws an error.
 // (When uploadAll() is used, the Uploader will
 // attempt to continue uploading.
 function onUploadError(event) {
 }
 
 // Do something if an upload is cancelled.
 function onUploadCancel(event) {
 }
 
 // Do something when data is received back from the server.
 function onUploadResponse(event) {
   YAHOO.log("Server response received.");
 }

</script>

</body>

 </source>
   
  
<A href="http://www.wbex.ru/Code/JavaScriptDownload/yui_2.7.0b.zip">yui_2.7.0b.zip( 4,431 k)</a>