The following Javascript code is used to upload one or more images from the PC to the server.

File location: /wsd-samples/uploadimages.js

<$if $prop:product$ eq "WSD Pro"><$setproperty local wsdpro="Yes">
<$elseif $prop:product$ eq "WSD Advanced"><$setproperty local wsdpro="Yes">
<$endif><script language="JavaScript">
<!--
var upload_directory;
var images_field;
var popup_win;
var upload_in_progress = false;

function init_upload()
{
   var xfile = document.UploadDocument.SAXFile;
   xfile.BackColor = 16510165;
}
function start_upload()
{
   if (upload_in_progress) alert('Upload is already in progress.');
   else if (popup_win.document.UploadDocument.SAXFile.Count > 0) {
      upload_in_progress = true;
      var xfile = popup_win.document.UploadDocument.SAXFile.XFRequest;
      xfile.Server = "<$prop:hostname$>";
<$if $prop:wsdpro$>      xfile.ObjectName = "<$prop:submiturl$>/uploadxfile";
<$else>      xfile.ObjectName = "<$prop:wsdurl$>/uploadxfile";
<$endif>      xfile.Timeout = 600;
      xfile.AddFormElement("UsingXFile","Yes");
      xfile.AddFormElement("_JavaScript","Yes");
      xfile.AddFormElement("_CurrentDir",upload_directory);
<$if $prop:wsdpro$>      xfile.AddFormElement("Stage","99");
      xfile.AddFormElement("_MenuReturn","");
<$endif>      xfile.AddFormElement("PopupClose","opener.update_images_list()");
      var window_opts = "height=300,width=400,status=no,toolbar=no,menubar=no,location=no";
      win = window.open('','uploading_image',window_opts);
      win.document.writeln('<html><head>');
      win.document.writeln('<script language="JavaScript">');
      win.document.writeln('function start_upload()');
      win.document.writeln('{');
      win.document.writeln('   var xfile = opener.popup_win.document.UploadDocument.SAXFile;');
      win.document.write('   document.SAXFileProgress.XFRequestStream = ');
      win.document.writeln('xfile.XFRequestStream;');
      win.document.writeln('   document.SAXFileProgress.BackColor = 16777215;');
      win.document.writeln('   document.SAXFileProgress.ShowProgress();');
      win.document.writeln('   xfile.Start();');
      win.document.writeln('   opener.popup_win.upload_in_progress = false;');
      win.document.writeln('   opener.popup_win.document.write(xfile.XFRequest.Response);');
      win.document.writeln('   opener.popup_win.document.close();');
      win.document.writeln('   window.close();');
      win.document.writeln('}');
      win.document.writeln('</script>');
      win.document.writeln('</head><body onload="start_upload()">');
      win.document.write('<OBJECT ID="SAXFileProgress" ');
      win.document.write('CLASSID="CLSID:C3EAF164-E06A-11D2-B5C9-0050041B7FF6">');
      win.document.writeln('</OBJECT>');
      win.document.writeln('</body></html>');
      win.document.close();
      win.focus();
   }
   else alert('There are no files to upload.');
}

function update_images_list() {
   var filenames_field = popup_win.document.OkForm.UploadedFilenames;
   var filenames;
   if (filenames_field) var filenames = filenames_field.value;
   else var filenames = "";
   if (filenames != "") {
      var length = images_field.length;
      var selected_image = length;
      while (filenames != "") {
         comma_pos = filenames.indexOf(",");
         if (comma_pos == -1) {
            filename = filenames;   filenames = "";
         }
         else {
            filename = filenames.substring(0,comma_pos);
            filenames = filenames.substring(comma_pos + 1,filenames.length);
         }
         while (filename.indexOf("\\") != -1) filename = filename.replace("\\","/");
         images_field.options[length] = new Option(filename,filename);
         length++;
      }
      images_field.selectedIndex = selected_image;
   }
   popup_win.close();
   upload_in_progress = false;
}

function upload_images(uploaddir,image_field_var) {
   upload_directory = uploaddir;
   images_field = image_field_var;
   var window_opts = 'toolbar=no,location=no,directories=no,status=no,' +
      'width=600,height=380,menubar=no,scrollbars=yes,resizable=yes';
   win = window.open('','upload_image',window_opts);
   popup_win = win;
   win.document.writeln('<html>');
   win.document.writeln('<head><title>Upload Images</title></head>');
   win.document.writeln('<body bgcolor="#D5ECFB">');
   win.document.writeln('<form name="UploadDocument">');
   win.document.writeln('<center>');
   win.document.writeln('<object classid="CLSID:230C3D02-DA27-11D2-8612-00A0C93EEA3C"');
   win.document.writeln('codebase="/wsd-support/cabs/SAXFile.cab#version=2,1,7,20333"');
   win.document.writeln('id="SAXFile" style="LEFT: 0px; TOP: 0px" height="300" width="550 VIEWASTEXT>');
   win.document.writeln('<param name="_cx" value="10239">');
   win.document.writeln('<param name="_cy" value="4895">');
   win.document.writeln('<param name="Appearance" value="0">');
   win.document.writeln('<param name="BackColor" value="16777215">');
   win.document.writeln('<param name="BackStyle" value="0">');
   win.document.writeln('<param name="BorderColor" value="3452816845">');
   win.document.writeln('<param name="BorderStyle" value="0">');
   win.document.writeln('<param name="Enabled" value="-1">');
   win.document.writeln('<param name="ForeColor" value="0">');
   win.document.writeln('<param name="HWND" value="0">');
   win.document.writeln('<param name="TabStop" value="-1">');
   win.document.writeln('</object><p>');
   win.document.writeln('<input type=button name="Upload" value="Upload" onClick="opener.start_upload();">');
   win.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
   win.document.writeln('<input type=button name="About" value="About XFile" onClick="document.UploadDocument.SAXFile.AboutBox();">');
   win.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
   win.document.writeln('<input type=button name="Cancel" value="Cancel" onClick="self.close();">');
   win.document.writeln('</form>');
   win.document.writeln('</body>');
   win.document.writeln('</html>');
   win.document.close();
   win.focus();
}
//-->
</script>

Copyright 2000-2005 CyberTeams, Inc., http://www.cyberteams.com All rights reserved.
CyberTeams and WebSite Director are registered trademarks of CyberTeams, Inc. All other marks are the property of their respective owners.