Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

ASP - File Rename when uploading files. (Pure ASP Upload)

OK.
  I am using the script from:
http://www.motobit.com/help/scptutl/pure-asp-upload.htm
Downloaded the version from here:
http://www.motobit.com/dlldownload/ScptUtl.exe (This will work on Winxp Pro IIS 5.1)

OK.
   What I am needing assistance on, is the File Renaming Function.
It will rename a file like so.
Existing File Name:   something else to do.jpg
New File Name:        something else to do-1.jpg

OK, what I am needing is for it to rename the file to something like this:
Existing File Name:   something else to do.jpg
New File Name:        something-else-to-do.jpg
If both exist then:     something-else-to-do-1.jpg  exc.... -2,-3,-4 and on and on for renaming.

This is the code that is being used for what I can gather.
Can anyone help out with this one?
Or suggest another renaming routine that will work just as well.
And this is very important, it must work cross platform.. This is very important.

As I am going to have to dump my old Uploading script as it will not work past IE6.
IE7 and above are dead to www.dmxzone.com Upload script. (Old Version dead, and the new version is having major problems)

This script that I am using now, works on everything that I have tested it with.

Thanks to all.
This is very important.
I do not have many points, but will award what I can to who came give me a working example.
(or) Pointing to a working example. (or) can fix this one for me.

I am going to research and see what I can find on my end.

Thanks
Carrzkiss
Function GetUniqueFileName(FileName, DestPath)
  if isempty(gFS) then Set gFS = CreateObject("Scripting.FileSystemObject")
  Dim DotPos: DotPos = InStrRev(FileName,".")
  if DotPos = 0 then DotPos = len(FileName)+1
  Dim Counter, FullPath, NewFileName
  Counter = 1
  NewFileName = FileName
  if gFS.FileExists(DestPath & "\" & NewFileName) then
    Do
      Counter = Counter + 1
      NewFileName = Left(FileName, DotPos-1) & "-" & Counter _
        & Mid(FileName, DotPos)
    Loop while gFS.FileExists(DestPath & "\" & NewFileName)
  end if
  GetUniqueFileName = NewFileName
End Function

Open in new window

Avatar of R_Harrison
R_Harrison
Flag of United Kingdom of Great Britain and Northern Ireland image

This should work for you.   No sure what value you where using for the DestPath, however this assumes the path starts from the root directory.  So to check in www.mydomain.com\pictures folder the value for DestPath would simply be "\pictures"
<%
Function GetUniqueFileName(FileName, DestPath)
	physicalpath=Server.MapPath(DestPath) & "\"
	Dim fs, f, f1, s, sf 
	Set fs = CreateObject("Scripting.FileSystemObject") 
	Set f = fs.GetFolder(physicalpath) 
	Set sf = f.SubFolders
	ReDim A_FileNames(0)	
	Set sf = f.files
	i=0
	For Each f1 in sf
		Redim Preserve A_FileNames(i)
		A_FileNames(i)=lcase(f1.name)
		i=i+1
	Next 
	FileName=lcase(Replace(FileName, " ", "-"))
	Rename="No"
	For x=0 to i-1
		If FileName=A_FileNames(x) Then Rename="Yes"
	Next
	If Rename="No" Then
		GetUniqueFileName=FileName
	Else
		ThisFile=Left(FileName, InstrRev(FileName, ".")-1)
		FileExtension=Right(FileName, Len(FileName)-InstrRev(FileName, ".")+1)
		Number=1
		Unique=false
		Do Until Unique
			Rename="No"
			For x=0 to i-1
				GetUniqueFileName=ThisFile & "-" & Number & FileExtension
				If GetUniqueFileName=A_FileNames(x) Then Rename="Yes"
			Next
			If Rename="No" Then
				Unique=True
			Else
				Number=Number+1
			End IF
		Loop
	End IF
End function
%>

Open in new window

Avatar of Wayne Barron

ASKER

Thank you R_Harrison:
I will check it after I get back from my son Dr. App.
He had brain surgery back in Nov. and his follow-up and MRI is today.
To get ready for his final surgery.

Anyway, Thank you so much in advance friend.
Carrzkiss
I am getting an error that I cannot seem to compile out of.
It is hitting on the
physicalpath=Server.MapPath(DestPath) & "\upload"

Server.MapPath() error 'ASP 0172 : 80004005'
Invalid Path
/Test/Pure/Samples/Upload-.asp, line 178
The Path parameter for the MapPath method must be a virtual path. A physical path was used.


The entire code will be listed below.
It is going to be hard to sypher through it all.
But this is for the Folder that is going to be used.
Dim DestinationPath
DestinationPath = Server.mapPath("PowderCoating_Pics")

It looks like there is going to have to be something else that is going to need to be done.
Hope you are still willing to help in this one with the code supplied,
And that you do not feel to over-whelmed with it all.

Thank you once again in advance.
(This is with your code added in. Along line: 176 with the original code listed right below it line: 219
<%      '@EnableSessionState=False
Option explicit
'Stores only files with size less than MaxFileSize
 
 
Const maxFileSize = 1500000 'limit of size per file
Const imageExts = ".gif,.jpg,.png,.jpeg,.bmp"
 
'Create the upload object
Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Dim Form: Set Form = New ASPForm '!--#INCLUDE FILE="_upload.asp"--><%
'Set the destination path - Path to store uploaded files.
Dim DestinationPath
DestinationPath = Server.mapPath("PowderCoating_Pics")
 
Server.ScriptTimeout = 2000
Form.SizeLimit = 4*1000000 'limit of size per whole form
 
 
'{b}Set the upload ID for this form.
'Progress bar window will receive the same ID.
if len(Request.QueryString("UploadID"))>0 then
  Form.UploadID = Request.QueryString("UploadID")'{/b}
end if
'was the Form successfully received?
Const fsCompletted  = 0
 
If Form.State = fsCompletted Then 'Completted
  Dim CustomerID
  CustomerID = Form("CustomerID")
 
  'Do something with upload - save, enumerate, ...
  response.write "<br><b>Upload result: Form was accepted.</b>" 
  response.write "<br>Number of file fields:" & Form.Files.Count
  response.write "<br>Request total bytes:" & Request.TotalBytes
 
  'PRocess files and create HTML report
  Dim OutHTML:  OutHTML = do_Files (Form)
 
  'Send the report by email
 ' SendReport NotifyAddress, "<body>" & OutHTML & "</body>"
 
  'Write the report to a client
  response.write OutHTML
 
ElseIf Form.State > 10 then
  Const fsSizeLimit = &HD
  Select case Form.State
    case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
    case else response.write "<br><Font Color=red>Some form error.</Font><br>"
  end Select
End If'Form.State = 0 then
 
 
 
 
Function do_Files (Form)
  Dim HTML
 
 
  '1. Process main upload fields - CustomerID, Description
  Dim UploadID, Uploads, CustomerID
  CustomerID = Form("CustomerID")
  if len(CustomerID)=0 then CustomerID = -1
 
  'DB contains two tables:
  ' - Uploads with UploadID (primary key), Description, and CustomerID
  ' - UploadsFiles with UploadID (foreign key), Description, DestFileName, DataSize and SourceFileName
  'Open table with list of uploads
  
  Set Uploads = OpenUploadRS("Uploads")
  Uploads.AddNew
    Uploads("Description") = Form("Description")
    Uploads("CustomerID") = CustomerID
  Uploads.Update
  UploadID = Uploads("UploadID")
 
  HTML = HTML & "<br>UploadID:" & UploadID
  HTML = HTML & "<br>CustomerID:" & Form("CustomerID")
 
  '2. Process form files
  Dim File
'  For Each File In Form.Files.Items
  For Each File In Form.Files
    If Len(File.FileName) > 0 Then
      
      'Open recordset to store uploaded files
      Dim UploadsFiles: Set UploadsFiles = OpenUploadRS("UploadsFiles")
 
      HTML = HTML &  "<br>File:" & File.FileName & ", size :" & (File.Length \ 1024 +1) & "kB"
      HTML = HTML &  ", Is image:" & IsImage(File)
      if File.Length > maxFileSize then
        HTML = HTML &  "<Font Color=red> exceeds the size limit  (" & maxFileSize & ").</font>" 
      elseif not IsImage(File) Then 
        HTML = HTML &  "<Font Color=red> is not an image type (" & imageExts & ").</font>" 
      else
        Dim DestFileName
        DestFileName = GetUniqueFileName(File.FileName, DestinationPath)
        File.SaveAs DestinationPath & "\" & DestFileName
 
        'Store extra info about upload to database
        UploadsFiles.AddNew
         UploadsFiles("UploadID") = UploadID
         UploadsFiles("SourceFileName") = left(File.FilePath,255)
         UploadsFiles("DestFileName") = left(DestFileName, 255)
         UploadsFiles("DataSize") = File.Length
         '...
        UploadsFiles.Update
 
        HTML = HTML &  "<Font Color=green> was stored to a disk as '" & DestFileName & "'.</font>"
      end if
    end if'if len(File.FileName)=0 then
 
  Next
'  Form.Files.Save DestinationPath 
  HTML = HTML &  "<br>Files was saved to " & DestinationPath & " folder."
  do_Files = HTML
End Function
 
 
'Send and upload report to administrator.
'Sub SendReport(NotifyAddress, Message)
'  SendMailCDO NotifyAddress, "Upload completted", Message, "", "webmaster@pcitdad.com"
 
'	if err<>0 then response.write "<br><font color=red>The CDONTS.NewMail object cannot be created to send notification.</font><br>"
'End Sub
 
 
 
Function OpenUploadRS(TableName)
  Dim RS  : Set RS = CreateObject("ADODB.Recordset")
  'Open dynamic recordset
  
  RS.Open TableName, GetConnection, 2, 2
  
  Set OpenUploadRS = RS
end Function 
 
Function GetConnection()
  dim Conn: Set Conn = CreateObject("ADODB.Connection")
  Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  Conn.open "Data Source=" & Server.MapPath("upload.mdb") 
  set GetConnection = Conn
end function
 
 
 
 
 
 
'This function checks filename and CONTENTS of a field
'to recognize images
Function IsImage(Field)
  IsImage = True 'I'm sorry, PureASP upload does not have HexString property.
  Exit Function
  if instr(1, imageExts & ",", Field.FileExt & ",", 1)>0 _
    or Left(Field.ContentType, 5) = "image" Then 
    
    ' FFD8FF = JFIF
    ' 49492A00 = TIF
    if Field.HexString (0,3)="FFD8FF" or Field.HexString (0,4)="49492A00" _
    or Field.String(,6,4)="JFIF" or Field.String(,0,3)="GIF" _
    or Field.String(,1,3)="PNG"  or Field.String(,0,2)="BM" then
      IsImage = True
    end if
  end if
End Function
 
 
 
 
 
Dim gFS
'creates an unique filename
'in filename.ext, filename-1.ext, filename-2.ext, filename-3.ext, ... schema
Function GetUniqueFileName(FileName, DestPath)
	'physicalpath=Server.MapPath(DestPath) & "\upload"
	physicalpath=Server.MapPath(DestPath) & "\"
	'(DestPath & "\" & NewFileName) 
	Dim fs, f, f1, s, sf 
	Set fs = CreateObject("Scripting.FileSystemObject") 
	Set f = fs.GetFolder(physicalpath) 
	Set sf = f.SubFolders
	ReDim A_FileNames(0)	
	Set sf = f.files
	i=0
	For Each f1 in sf
		Redim Preserve A_FileNames(i)
		A_FileNames(i)=lcase(f1.name)
		i=i+1
	Next 
	FileName=lcase(Replace(FileName, " ", "-"))
	Rename="No"
	For x=0 to i-1
		If FileName=A_FileNames(x) Then Rename="Yes"
	Next
	If Rename="No" Then
		GetUniqueFileName=FileName
	Else
		ThisFile=Left(FileName, InstrRev(FileName, ".")-1)
		FileExtension=Right(FileName, Len(FileName)-InstrRev(FileName, ".")+1)
		Number=1
		Unique=false
		Do Until Unique
			Rename="No"
			For x=0 to i-1
				GetUniqueFileName=ThisFile & "-" & Number & FileExtension
				If GetUniqueFileName=A_FileNames(x) Then Rename="Yes"
			Next
			If Rename="No" Then
				Unique=True
			Else
				Number=Number+1
			End IF
		Loop
	End IF
End function
 
'this is the start of the original code.
'Function GetUniqueFileName(FileName, DestPath)
'  if isempty(gFS) then Set gFS = CreateObject("Scripting.FileSystemObject")
'  Dim DotPos: DotPos = InStrRev(FileName,".")
'  if DotPos = 0 then DotPos = len(FileName)+1
'  Dim Counter, FullPath, NewFileName
'  Counter = 1
'  NewFileName = FileName
'  if gFS.FileExists(DestPath & "\" & NewFileName) then
'    Do
'      Counter = Counter + 1
'      NewFileName = Left(FileName, DotPos-1) & "-" & Counter _
'        & Mid(FileName, DotPos)
'    Loop while gFS.FileExists(DestPath & "\" & NewFileName)
'  end if
'  GetUniqueFileName = NewFileName
'End Function
 
%>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
 <TITLE>ASP huge file upload - Image upload, combine several upload features.</TITLE>
 <STYLE TYPE="text/css"><!--TD  {font-family:Arial,Helvetica,sans-serif }TH  {font-family:Arial,Helvetica,sans-serif }TABLE  {font-size:10pt;font-family:Arial,Helvetica,sans-serif }--></STYLE>
 <meta name="robots" content="noindex,nofollow">
</HEAD>
<BODY BGColor=white>
 
 
<Div style=width:600>
 
 
<TABLE cellSpacing=1 cellPadding=3 bordercolor=silver bgcolor=GAINSBORO width="" border=1>
<form name="file_upload" method=post ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar(this);">
<input type=hidden name=CustomerID Value="<%=CustomerID%>">
<TR>
 <TD>&nbsp;</TD>
 <TD Align=Right><input type="submit" Name="Action" value="Upload these images &gt;&gt;"></TD>
</TR>
<TR>
 <TD>Description</TD>
 <TD><input size=40 Name="Description" value=""></TD>
</TR>
<TR>
 <TD NoWrap>Images to upload<br><Input Type=Button Value="Add an image" OnClick=return(Expand()) 
 Style="border=0;background=yellow;cursor:hand"></TD>
 <TD>
<Div ID=files>
 <div id=dfile1>
   Image 1 : <input type="file" name="Image 1" id="Image 1" onChange="preview(1)" onFocus="preview(1)"><img id="himg1" style="display:none" onload="himgLoaded(1)"> Size:&nbsp;<span id="size1">-</span><br>
 </div>
   Image 2 : <input type="file" name="Image 2" id="Image 2" onChange="preview(2)" onFocus="preview(2)"><img id="himg2" style="display:none" onload="himgLoaded(2)"> Size:&nbsp;<span id="size2">-</span><br>
   Image 3 : <input type="file" name="Image 3" id="Image 3" onChange="preview(3)" onFocus="preview(3)"><img id="himg3" style="display:none" onload="himgLoaded(3)"> Size:&nbsp;<span id="size3">-</span><br>
</Div>
 Total size:&nbsp;<span id="totalSize">-</span>
</TD>
</TR>
<!--<TR>
 <TD>Description</TD>
 <TD><textarea cols="60" rows="3" name="Description">Type description of the image upload.</textarea></TD>
</TR>-->
<tr><td><Div ID=ImageName>Image preview :</Div></td><td>
<img border="0" width="0" ID="ipreview" src="">
</td></tr>
</form></Table>
 
 
 
 
 
 
<SCRIPT>
//Open window with progress bar.
//pair upload window and progress window (using UploadID).
function ProgressBar(form){
 //check file sizes.
 
 if (checkFileSize()) {
   alert('Upload size is over limit. Please check selected files.')
   return false;
 };
 
  
 //ASP script handling progress window
 var ProgressScript
 ProgressScript = 'progress.asp'
 
 
 //Progress window parameters
 var pp = 'toolbar=no,location=no,directories=no,status=no,menubar=no'
 pp+=',scrollbars=no,resizable=yes,width=350,height=200';
  
 //1. Get unique UploadID
 var UploadID
 UploadID = Math.round(Math.random() * 0x7FFFFFF0)
  
 //2. Add upload ID to form action URL
 var action = form.action;
 if ('' == action) action = ''+document.location;
 action = AddToQuery(action, 'UploadID', UploadID);
 form.action = action
 
 //3. Open progress window with the same UploadID
 var ProgressURL
 ProgressURL = ProgressScript + '?UploadID=' + UploadID 
 
 var v = window.open(ProgressURL,'_blank',pp)
 
 return true;
};
 
//Adds value and its name to querystring
function AddToQuery(q, valname, val){
 if (q.indexOf('?')<0) {
   q += '?'
 } else {
 var pv = q.indexOf(valname+'=');
 if (pv >= 0){
  var amp = q.indexOf('&', pv);
  if (amp<0) {
   q = q.substr(0, pv) 
  } else {
   q = q.substr(0, pv) + q.substr(amp+1) + '&'
  }
 } else {
  if (q.substr(q.length-1)!='?') q += '&'
 };
 };
 q += valname + '=' + val
 return q
};
</SCRIPT> 
 
 
<Script>
//Additional function - dynamic form to add new files at a client side.
 
var nfiles = 3;
//Add two files for upload
//Expand();
function Expand(){
  
  //get an HTML code of a first upload element
  var adh = dfile1.outerHTML;
 
  //replace '1' to nfiles (2, 3, ...)
  adh = adh.replace(/1/g,++nfiles)
  
  //insert the code of a new element before end of div files
  files.insertAdjacentHTML('BeforeEnd',adh);
 
  //clear mask and real value of the element nfiles
  //document.getElementById('maskfile'+nfiles).value=''
  return false;
};
 
</Script>
 
 
<Script>
//Huge-asp upload preview sample
//http://www.motobit.com
 
function isImage(file){
  //Get a file extension
  var ext = file.substr(file.lastIndexOf('.')).toLowerCase()
 
  //Check extension to image types.
  
  return '<%=imageExts%>,'.indexOf(ext+',') >= 0
};
 
var lastfieldname = ''
var filenamechecked = ''
function preview(n) {
  //get current input preview
  var htmlfile = document.getElementById('Image '+n);
  var file = htmlfile.value
 
  //set the size field.
  var himg = document.getElementById('himg'+n);
  if (file.length>0) himg.src = 'file://' + file;
  else { 
    himg.src = ''; 
    document.getElementById('size'+n).innerHTML='-'
  };
  
  if (file.length<=0) return;
 
  //or get get preview for one of form field
  //var file = file_upload.SourceFile1.value
  var ipreview = document.getElementById('ipreview');
  
  //do not check the file more than one.
  if (filenamechecked != htmlfile.value) {
    filenamechecked = htmlfile.value
  } else {
    return true;
  };
 
  if (isImage(file)) {
 
    //Show preview for the image.
    ipreview.src = 'file://' + file
    //alert(file);
    //alert(ipreview.src);
    ipreview.title = 'Image ' + file 
    if (ipreview.width != 300) ipreview.width = 300;
 
    ImageName.innerHTML = 'Image preview<br>(' + htmlfile.name + ')'
  } else {
    //some default image for preview
    ipreview.src = 'res://shdoclc.dll/warning.gif'
 
    alert('Please choose some image file (<%=imageExts%>)');
    
  };
  
  lastfieldname = htmlfile.name
}
 
function himgLoaded(n){
  checkFileSize();
};
 
 
//this function gets a sizes of images,
//write the sizes to HTML form
//counts total size and checks file sizes against a limit
var maxFileSize = <%=maxFileSize%>
var FormSizeLimit = <%=Form.SizeLimit%>
function checkFileSize() {
  var totalSize = 0;
  var htmlSize;
  var overLimit = false;
  for (j = 1; j <= nfiles; j++) {
    var himg = document.getElementById('himg'+j);
    var size = document.getElementById('size'+j);
    var fileSize = himg.fileSize ;
 
    fileSize = parseInt(fileSize);
    
    if (fileSize < 0) {
      size.innerHTML = '-';
    } else {
      htmlSize = formatSize(fileSize);
      if ( fileSize>maxFileSize ) {
        htmlSize += ' (over limit, ' + formatSize(maxFileSize) + ' max)'
        size.style.color = 'red';
        overLimit = true;
      } else {
        size.style.color = '';
      };
      size.innerHTML = htmlSize;
      totalSize += fileSize;
    };//if (fileSize < 0) {
  };//for (j = 1; j <= nfiles; j++)
 
 
  var htotalSize = document.getElementById('totalSize');
  
  if (totalSize > 0){
    htmlSize = formatSize(totalSize);
  } else {
    htmlSize = '-';
  };
  if (totalSize > FormSizeLimit) {
    htotalSize.style.color = 'red';
    htmlSize += ' (over limit, ' + formatSize(FormSizeLimit) + ' max)'
    overLimit = true;
  } else {
    htmlSize += ' (of ' + formatSize(FormSizeLimit) + ' max)'
  };
  htotalSize.innerHTML = htmlSize
  return overLimit;
};
 
function formatSize(size) {
  if (size < 0x100000) {// < 1 MB
    return Math.round(size / 0x400)+"&nbsp;kB"; 
  } else { // > 1 MB
    return (Math.round((size / 0x100000)*10)/10)+"&nbsp;MB";
  }
}
 
 
//window.onerror = donotmsgboxes;
function donotmsgboxes(msg,url,line)
{  // we do not need error messages
  return true
}
 
</Script>
 
 
<br><br>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  
  <TR>
    <TH noWrap align=left width="20%" bgColor=khaki>&nbsp;<A 
      href="http://www.motobit.com/help/scptutl/upload.asp">Huge ASP 
      file upload</A> -  Image upload, combine several upload features.&nbsp;</TH>
    <TD>&nbsp;</TD></TR></TABLE>
 
 
<TABLE cellSpacing=2 cellPadding=1 width="100%" bgColor=white border=0>
  
  <TR>
    <TD colSpan=2>
      <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This sample demonstrates several Huge-ASP file upload features.
      <li><b>Client-side preview of images</b> - client-side JavaScript shows preview of an image when user choose some image. 
      Client can see images before upload
      <li><b>Client-side check of file extensions</b> - File extensions are checked before upload. If the extension is not in '<%=imageExts%>' list, client get a warning message.
      <li><b>Client-side check of file and form size</b> - the source form size and size of each file field is checked BEFORE the form is sent. So the client do not need to send the form to see if the size of files/upload is correct.
       <br>&nbsp;&nbsp;&nbsp;- Limit for whole form is set to <%=Form.SizeLimit%> Bytes
       <br>&nbsp;&nbsp;&nbsp;- Limit per file is set to <%=maxFileSize%> Bytes
      <li><b>Upload with progress bar</b> - This script shows progress bar immediatelly after 'Upload' click. Client can immediatelly see that upload starts and then can see progress of the upload. 
      <li><b>Server side checking for form and file size</b>
       <br>&nbsp;&nbsp;&nbsp;- Limit for whole form is set to <%=Form.SizeLimit%> Bytes
       <br>&nbsp;&nbsp;&nbsp;- Limit per file is set to <%=maxFileSize%> Bytes
      <li><b>Server side checking for file extensions and content-type</b> File extensions are checked AFTER upload once again (to handle situation when client-side script is off). If the extension is not in '<%=imageExts%>' list or content-type is not 'image/...', file is not stored on server-side
      <li><b>Server side checking of a file CONTENTS</b> <%=imageExts%> files have a special contents characteristics. This script also checks the CONTENTS of a file to be sure that the file is not an .exe renamed to .gif or .jpg. The file is stored ONLY if it is REALLY an image. (see IsImage function inside this source)
      <li><b>Save files with unique file names</b> - each correct image file is stored. If same old-file exists on server-side, new file with the same name is stored with unique file name (GetUniqueFileName function inside this script)
      <li><b>Store upload info to a database</b> - This script also stores info about upload and each uploaded file to a database
      <li><b>Send administrator email notification</b> - This script creates an HTML report about upload and the report is sent to administrator email.
       
      <br><br>Destination folder is <%=DestinationPath%>
<br>Administrator email address (notification email) is <b><%=NotifyAddress%></b>. You can change the address in the source code of this ASP file. 
 
      <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; See also:
      <li><A Href="default.htm">List of samples</A>
      <li><A Href="Upload-Progress.ASP">Base upload with progress bar</A>
      <li><A Href="Progress-Galery\Upload-ProgressGal.ASP">Progress bar gallery</A>
      <li><A Href="Upload-Images-FileSize-Unique-Notification.ASP">Upload images with preview, progress and checking</A>
      <li><A Href="Upload-Email.ASP">Upload to email</A>
      </P>
  </TD></TR></TABLE>
 
 
<HR COLOR=silver Size=1>
<CENTER>
<FONT SIZE=1>&copy; 1996  <%=year(date)%> Antonin Foller, <a href="http://www.motobit.com">Motobit Software</a>, e-mail <A href="mailto:help@pstruh.cz" >help@pstruh.cz</A>
<br>To monitor current running uploads/downloads, see <A Href="http://www.motobit.com/help/iistrace/iis-monitor.asp">IISTracer - IIS real-time monitor</A>.
</FONT>
 
</CENTER>
</Div>
</BODY></HTML>
<%
'This function sends an email message from a local computer, 
' using CDONTS.NewMail or CDO.Message, through IIS SMTP service
' 2006 Antonin Foller, Motobit Software.
Sub SendMailCDO(aTo, Subject, TextBody, byval FileNames, aFrom)
  if not isarray(FileNames) then FileNames = split(FileNames, ",")
 
  Const cdoOutlookExvbsss = 2
  Const cdoIIS = 1
  Const CdoMailFormatMime = 0
  Const cdoSendUsingPort = 2
 
  Dim Message, CDONTS
 
  on error resume next
 
  'Create a new email message
  Set Message = CreateObject("CDONTS.NewMail")
 
  if err = 0 then 'there is CDONTS.NewMail object.
    CDONTS = True
 
    Message.MailFormat = CdoMailFormatMime
 
  else 'use CDO.Message instead
    CDONTS = False
 
    'Create CDO message object
    Set Message = CreateObject("CDO.Message")
 
    'Load IIS configuration
    'Message.Configuration.Load cdoIIS
    'Set configuration fields. 
    With Message.Configuration.Fields
      'Original sender email address 
      .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = aFrom
 
      'SMTP settings - without authentication, using standard port 25 on host smtp
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
 
      'SMTP Authentication
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
 
      .Update
    End With
  end if
  on error goto 0
 
  With Message
    'Set from, to and subject (common properties for newmail and message objects)
    .From = aFrom
    .To = aTo
    .Subject = Subject
 
    'Add attachments
    Dim File 
    For Each File In FileNames
      if CDONTS then
        .AttachFile File
      else
        .AddAttachment File
      end if
    Next
 
    'Set body of the message (different for newmail and message )
    if CDONTS then
      .Body = TextBody
    else
      if instr(1, TextBody, "<body>", 1)>0 then' the TextBody has HTML format.
        .htmlBody = TextBody
      else
        .TextBody = TextBody
      end if
    end if
    
    
    .Send
  End With
End Sub
 
%>

Open in new window

OK, the problem is the value DestPath that you are using to call the function.   The DesPath value you are passing is already a physical path e.g c:\inetpub\powdercoating_pics not a virtual path e.g \PowderCoating_pics - I can see this as you already do a server.mappath on line 14 and use this as the value to call the function.

Therefore if you change line 98 to...

DestFileName = GetUniqueFileName(File.FileName, "\PowderCoating_Pics")

It should work.
Or is you wanted it to check the files in the directory  \PowderCoating_Pics\Upload change it to

DestFileName = GetUniqueFileName(File.FileName, "\PowderCoating_Pics\Upload")
OK.
  I changed the line mentioned above, and it compiled through and this time
It gives me
physicalpath is undefined

So I added it to the
Dim gFS,  physicalpath

And it does not give me an error, but when a file is uploaded, it never completes the upload
And it crashes IIS and I have to Restart IIS.

Hopefully we can get this one kicked, I would really love to be able to hand the site back over
To the users, and get it out of my hair for the weekend, so i can do other things.

Thank you once again for all your help.
And hopefully you are around right now, to assist me further.
As I see that you only reply around the 4:00 time period, so many you are still around.

Take Care
Wayne
Can you comment our line 2, Option explicit and let me know what happens?
Sorry typo, should have been comment out, line 2. Option explicit
I think the problem is that we haven't declared are the variables in the function I wrote as I didn't realise you were using option explicit.
I commented it out, and it still does the same thing.
What all needs to be declared, i added in the following and still the same results.
Dim fs, f, f1, s, sf, i, x
Hello R_Harrison:
Hope that you had a good weekend?
Just wondering if you had an opertunity of looking back at this issue yet?
If you can assist to a resolution, I will award you 500=2000 Points.
I just really need to get this thing working, as it is eating away at me.

What is so aggrivating for me, is that I have been able to figure out all my other issues
As soon as I have posted here on EE, and once I figure it out, I [Delete] my post.
In this case, I cannot grasp this code, but it seems that this is the only "Free" code that
Will work across-platforms. (IE, FireFox, and so on)

Thank you once again for all your help.
Wayne
Sorry, for the delay I have been away for a long weekend and could not get an internet connection.

Below is the revised function which should work with the option explicit.
Function GetUniqueFileName(FileName, DestPath)
	dim fs, f, f1, s, sf 
	dim physicalpath, i, x, ThisFile, FileExtension, Unique, Rename, Number
	physicalpath=Server.MapPath(DestPath) & "\"
	Set fs = CreateObject("Scripting.FileSystemObject") 
	Set f = fs.GetFolder(physicalpath) 
	Set sf = f.SubFolders
	ReDim A_FileNames(0)	
	Set sf = f.files
	i=0
	For Each f1 in sf
		Redim Preserve A_FileNames(i)
		A_FileNames(i)=lcase(f1.name)
		i=i+1
	Next 
	FileName=lcase(Replace(FileName, " ", "-"))
	Rename="No"
	For x=0 to i-1
		If FileName=A_FileNames(x) Then Rename="Yes"
	Next
	If Rename="No" Then
		GetUniqueFileName=FileName
	Else
		ThisFile=Left(FileName, InstrRev(FileName, ".")-1)
		FileExtension=Right(FileName, Len(FileName)-InstrRev(FileName, ".")+1)
		Number=1
		Unique=false
		Do Until Unique
			Rename="No"
			For x=0 to i-1
				GetUniqueFileName=ThisFile & "-" & Number & FileExtension
				If GetUniqueFileName=A_FileNames(x) Then Rename="Yes"
			Next
			If Rename="No" Then
				Unique=True
			Else
				Number=Number+1
			End IF
		Loop
	End IF
End function
%>

Open in new window

that is absolutely fine.
I had to deal with other things as well.

Going to test the code. Fingers crossed :)
:(
Sad but true.
  Still the same results.
Once the code is inserted, and the page is run.
The Progress Dialog opens, and it does a continues loop.
And the main window, just hangs.
Which causes me to have to restart IIS again.

And in this case, my IIS will not allow me to restart it due to an error.
[No Such Interface Supported]
So I am off to fix this issue now.

If it is not one thing it is another right?

have a good one friend.
Wayne
OK, I tested the code and it ran fine, does you IIS show any errors?
No Errors.
What do you mean is IIS showing any errors?
The ASP is not throwing any errors.

Can you perhaps send over the full working code that you are using?
There has to be something a miss in my code, unless it is an issue with my system setup itself?

I am testing this code on: WinXP SP3 IIS5.1 All updates.
Sorry, for the delay will post soon, I just has a client change deadlines and have had to work flat out to meet the new deadline!
No problem at all.
OK, can you copy the code below onto a new page on your server.   This is just the unique file name function and should simply show the unique file name.   If this work we need to look at the rest of your code, if it hangs then we will need to look as your server logs to find out why.   I have tested the code and it runs fine.
<%
Option explicit
dim file
 
file=GetUniqueFileName("Default.asp", "/")
response.write(file)
 
 
Function GetUniqueFileName(FileName, DestPath)
	dim fs, f, f1, s, sf 
	dim physicalpath, i, x, ThisFile, FileExtension, Unique, Rename, Number
	physicalpath=Server.MapPath(DestPath) & "\"
	Set fs = CreateObject("Scripting.FileSystemObject") 
	Set f = fs.GetFolder(physicalpath) 
	Set sf = f.SubFolders
	ReDim A_FileNames(0)	
	Set sf = f.files
	i=0
	For Each f1 in sf
		Redim Preserve A_FileNames(i)
		A_FileNames(i)=lcase(f1.name)
		i=i+1
	Next 
	FileName=lcase(Replace(FileName, " ", "-"))
	Rename="No"
	For x=0 to i-1
		If FileName=A_FileNames(x) Then Rename="Yes"
	Next
	If Rename="No" Then
		GetUniqueFileName=FileName
	Else
		ThisFile=Left(FileName, InstrRev(FileName, ".")-1)
		FileExtension=Right(FileName, Len(FileName)-InstrRev(FileName, ".")+1)
		Number=1
		Unique=false
		Do Until Unique
			Rename="No"
			For x=0 to i-1
				GetUniqueFileName=ThisFile & "-" & Number & FileExtension
				If GetUniqueFileName=A_FileNames(x) Then Rename="Yes"
			Next
			If Rename="No" Then
				Unique=True
			Else
				Number=Number+1
			End IF
		Loop
	End IF
End function
%>

Open in new window

This sucks.

It will work on our Hosting Server, but not on my [XP Pro IIS 5.1]
So, it is something wrong with my system (or) IIS5.1

I have checked to see if there was anything that was missing for install
I installed the Frontpage extensions.
And did a check online to see if I could find out what else I would need.
And every resource that I find says that everything should be current.

So, lets take a look at my configuration.

Once we have this one done.
I am going to make another post, and direct it to you.
As this is a nightmare, and getting worse.

Thank you for taking the time to help me.
Wayne
OK, are you running any anti-virus programs.  Specifically Nortons Antivirus?  If so make sure Script Blocking allows the FSO to run as Nortons has been known to see this as a potential threat - may also apply to other AntiVirus programs but I know Nortons can do this.
OK
That made the script run, without an issue, which a GREAT thing!!!!!!!!!!!! Thank you for that.

Now.
I am getting this error:
==========================================
Microsoft VBScript runtime error '800a004c'
Path not found
/Test/Pure/Samples/Upload-.asp, line 182
==========================================
Line 182:               Set f = fs.GetFolder(physicalpath)

This is the physicalpath
physicalpath=Server.MapPath(DestPath) & "\"

I tried to change it to the folder itself:
physicalpath=Server.MapPath(DestPath) & "\images"
&
physicalpath=Server.MapPath(DestPath) & "image"

And I still get the same error.

I did some checking and on 1 site it is talking about the C:\temp Folder.
Which should not have nothing to do with this issue. (Should It?)

I also have WRITE permissions on this folder with IUSR

The c:\temp folder has nothing to do with us, you can use any folder.  Trying adding the slash at the end of the folder e.g physicalpath=Server.MapPath(DestPath) & "\images\"

Glad we got the script to run without hanging your server :-)
Yep.
That is nice to finally run it without the Hanging issue.

I changed the Slashes and nothing worked.
Still getting the same error.
OK, the problem is that it cannot find the path, this is because it is asking to list the folders in the file upload-.asp which of course is nonsense.   Somewhere in the code your physicalpath=Server.MapPath(DestPath) & "\images\ is being turned into /Test/Pure/Samples/Upload-.asp probably we are just using the wrong variable or have a problem with using the same variable name for 2 things.

Can you repost your code as it is, as I no longer know what line 182 is?   Once I get your reposted code I should be able to give you a fully working solution :-) now the hanging issue is solved.
OK.
Here is the code.
I have ran into this type of issue before, with the other Upload source that I was using.
But cannot remember what I did to over-come it.
As it was about 4yrs ago.

Thanks once again for all your help.
Wayne
<%      '@EnableSessionState=False
'Option explicit
'Stores only files with size less than MaxFileSize
 
 
Const maxFileSize = 1500000 'limit of size per file
Const imageExts = ".gif,.jpg,.png,.jpeg,.bmp"
 
'Create the upload object
Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Dim Form: Set Form = New ASPForm '!--#INCLUDE FILE="_upload.asp"--><%
'Set the destination path - Path to store uploaded files.
Dim DestinationPath
DestinationPath = Server.mapPath("PowderCoating_Pics")
'physicalpath=Server.MapPath(DestPath) & "\PowderCoating_Pics\"
 
Server.ScriptTimeout = 2000
Form.SizeLimit = 4*1000000 'limit of size per whole form
 
 
'{b}Set the upload ID for this form.
'Progress bar window will receive the same ID.
if len(Request.QueryString("UploadID"))>0 then
  Form.UploadID = Request.QueryString("UploadID")'{/b}
end if
'was the Form successfully received?
Const fsCompletted  = 0
 
If Form.State = fsCompletted Then 'Completted
  Dim CustomerID
  CustomerID = Form("CustomerID")
 
  'Do something with upload - save, enumerate, ...
  response.write "<br><b>Upload result: Form was accepted.</b>" 
  response.write "<br>Number of file fields:" & Form.Files.Count
  response.write "<br>Request total bytes:" & Request.TotalBytes
 
  'PRocess files and create HTML report
  Dim OutHTML:  OutHTML = do_Files (Form)
 
  'Send the report by email
 ' SendReport NotifyAddress, "<body>" & OutHTML & "</body>"
 
  'Write the report to a client
  response.write OutHTML
 
ElseIf Form.State > 10 then
  Const fsSizeLimit = &HD
  Select case Form.State
    case fsSizeLimit: response.write  "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
    case else response.write "<br><Font Color=red>Some form error.</Font><br>"
  end Select
End If'Form.State = 0 then
 
 
 
 
Function do_Files (Form)
  Dim HTML
 
 
  '1. Process main upload fields - CustomerID, Description
  Dim UploadID, Uploads, CustomerID
  CustomerID = Form("CustomerID")
  if len(CustomerID)=0 then CustomerID = -1
 
  'DB contains two tables:
  ' - Uploads with UploadID (primary key), Description, and CustomerID
  ' - UploadsFiles with UploadID (foreign key), Description, DestFileName, DataSize and SourceFileName
  'Open table with list of uploads
  
  Set Uploads = OpenUploadRS("Uploads")
  Uploads.AddNew
    Uploads("Description") = Form("Description")
    Uploads("CustomerID") = CustomerID
  Uploads.Update
  UploadID = Uploads("UploadID")
 
  HTML = HTML & "<br>UploadID:" & UploadID
  HTML = HTML & "<br>CustomerID:" & Form("CustomerID")
 
  '2. Process form files
  Dim File
'  For Each File In Form.Files.Items
  For Each File In Form.Files
    If Len(File.FileName) > 0 Then
      
      'Open recordset to store uploaded files
      Dim UploadsFiles: Set UploadsFiles = OpenUploadRS("UploadsFiles")
 
      HTML = HTML &  "<br>File:" & File.FileName & ", size :" & (File.Length \ 1024 +1) & "kB"
      HTML = HTML &  ", Is image:" & IsImage(File)
      if File.Length > maxFileSize then
        HTML = HTML &  "<Font Color=red> exceeds the size limit  (" & maxFileSize & ").</font>" 
      elseif not IsImage(File) Then 
        HTML = HTML &  "<Font Color=red> is not an image type (" & imageExts & ").</font>" 
      else
        Dim DestFileName
		DestFileName = GetUniqueFileName(File.FileName, "\PowderCoating_Pics")
        'DestFileName = GetUniqueFileName(File.FileName, DestinationPath)
        File.SaveAs DestinationPath & "\" & DestFileName
 
        'Store extra info about upload to database
        UploadsFiles.AddNew
         UploadsFiles("UploadID") = UploadID
         UploadsFiles("SourceFileName") = left(File.FilePath,255)
         UploadsFiles("DestFileName") = left(DestFileName, 255)
         UploadsFiles("DataSize") = File.Length
         '...
        UploadsFiles.Update
 
        HTML = HTML &  "<Font Color=green> was stored to a disk as '" & DestFileName & "'.</font>"
      end if
    end if'if len(File.FileName)=0 then
 
  Next
'  Form.Files.Save DestinationPath 
  HTML = HTML &  "<br>Files was saved to " & DestinationPath & " folder."
  do_Files = HTML
End Function
 
 
'Send and upload report to administrator.
'Sub SendReport(NotifyAddress, Message)
'  SendMailCDO NotifyAddress, "Upload completted", Message, "", "webmaster@pcitdad.com"
 
'	if err<>0 then response.write "<br><font color=red>The CDONTS.NewMail object cannot be created to send notification.</font><br>"
'End Sub
 
 
 
Function OpenUploadRS(TableName)
  Dim RS  : Set RS = CreateObject("ADODB.Recordset")
  'Open dynamic recordset
  
  RS.Open TableName, GetConnection, 2, 2
  
  Set OpenUploadRS = RS
end Function 
 
Function GetConnection()
  dim Conn: Set Conn = CreateObject("ADODB.Connection")
  Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  Conn.open "Data Source=" & Server.MapPath("upload.mdb") 
  set GetConnection = Conn
end function
 
 
 
 
 
 
'This function checks filename and CONTENTS of a field
'to recognize images
Function IsImage(Field)
  IsImage = True 'I'm sorry, PureASP upload does not have HexString property.
  Exit Function
  if instr(1, imageExts & ",", Field.FileExt & ",", 1)>0 _
    or Left(Field.ContentType, 5) = "image" Then 
    
    ' FFD8FF = JFIF
    ' 49492A00 = TIF
    if Field.HexString (0,3)="FFD8FF" or Field.HexString (0,4)="49492A00" _
    or Field.String(,6,4)="JFIF" or Field.String(,0,3)="GIF" _
    or Field.String(,1,3)="PNG"  or Field.String(,0,2)="BM" then
      IsImage = True
    end if
  end if
End Function
 
 
 
 
 
Dim gFS, physicalpath
'creates an unique filename
'in filename.ext, filename-1.ext, filename-2.ext, filename-3.ext, ... schema
Function GetUniqueFileName(FileName, DestPath)
	dim fs, f, f1, s, sf 
	dim physicalpath, i, x, ThisFile, FileExtension, Unique, Rename, Number
	physicalpath=Server.MapPath(DestPath) & "PowderCoating_Pics"
	Set fs = CreateObject("Scripting.FileSystemObject") 
	Set f = fs.GetFolder(physicalpath) 
	Set sf = f.SubFolders
	ReDim A_FileNames(0)	
	Set sf = f.files
	i=0
	For Each f1 in sf
		Redim Preserve A_FileNames(i)
		A_FileNames(i)=lcase(f1.name)
		i=i+1
	Next 
	FileName=lcase(Replace(FileName, " ", "-"))
	Rename="No"
	For x=0 to i-1
		If FileName=A_FileNames(x) Then Rename="Yes"
	Next
	If Rename="No" Then
		GetUniqueFileName=FileName
	Else
		ThisFile=Left(FileName, InstrRev(FileName, ".")-1)
		FileExtension=Right(FileName, Len(FileName)-InstrRev(FileName, ".")+1)
		Number=1
		Unique=false
		Do Until Unique
			Rename="No"
			For x=0 to i-1
				GetUniqueFileName=ThisFile & "-" & Number & FileExtension
				If GetUniqueFileName=A_FileNames(x) Then Rename="Yes"
			Next
			If Rename="No" Then
				Unique=True
			Else
				Number=Number+1
			End IF
		Loop
	End IF
End function
 
 
 
'this is the start of the original code.
'Function GetUniqueFileName(FileName, DestPath)
'  if isempty(gFS) then Set gFS = CreateObject("Scripting.FileSystemObject")
'  Dim DotPos: DotPos = InStrRev(FileName,".")
'  if DotPos = 0 then DotPos = len(FileName)+1
'  Dim Counter, FullPath, NewFileName
'  Counter = 1
'  NewFileName = FileName
'  if gFS.FileExists(DestPath & "\" & NewFileName) then
'    Do
'      Counter = Counter + 1
'      NewFileName = Left(FileName, DotPos-1) & "-" & Counter _
'        & Mid(FileName, DotPos)
'    Loop while gFS.FileExists(DestPath & "\" & NewFileName)
'  end if
'  GetUniqueFileName = NewFileName
'End Function
 
%>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
 <TITLE>ASP huge file upload - Image upload, combine several upload features.</TITLE>
 <STYLE TYPE="text/css"><!--TD  {font-family:Arial,Helvetica,sans-serif }TH  {font-family:Arial,Helvetica,sans-serif }TABLE  {font-size:10pt;font-family:Arial,Helvetica,sans-serif }--></STYLE>
 <meta name="robots" content="noindex,nofollow">
</HEAD>
<BODY BGColor=white>
 
 
<Div style=width:600>
 
 
<TABLE cellSpacing=1 cellPadding=3 bordercolor=silver bgcolor=GAINSBORO width="" border=1>
<form name="file_upload" method=post ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar(this);">
<input type=hidden name=CustomerID Value="<%=CustomerID%>">
<TR>
 <TD>&nbsp;</TD>
 <TD Align=Right><input type="submit" Name="Action" value="Upload these images &gt;&gt;"></TD>
</TR>
<TR>
 <TD>Description</TD>
 <TD><input size=40 Name="Description" value=""></TD>
</TR>
<TR>
 <TD NoWrap>Images to upload<br><Input Type=Button Value="Add an image" OnClick=return(Expand()) 
 Style="border=0;background=yellow;cursor:hand"></TD>
 <TD>
<Div ID=files>
 <div id=dfile1>
   Image 1 : <input type="file" name="Image 1" id="Image 1" onChange="preview(1)" onFocus="preview(1)"><img id="himg1" style="display:none" onload="himgLoaded(1)"> Size:&nbsp;<span id="size1">-</span><br>
 </div>
   Image 2 : <input type="file" name="Image 2" id="Image 2" onChange="preview(2)" onFocus="preview(2)"><img id="himg2" style="display:none" onload="himgLoaded(2)"> Size:&nbsp;<span id="size2">-</span><br>
   Image 3 : <input type="file" name="Image 3" id="Image 3" onChange="preview(3)" onFocus="preview(3)"><img id="himg3" style="display:none" onload="himgLoaded(3)"> Size:&nbsp;<span id="size3">-</span><br>
</Div>
 Total size:&nbsp;<span id="totalSize">-</span>
</TD>
</TR>
<!--<TR>
 <TD>Description</TD>
 <TD><textarea cols="60" rows="3" name="Description">Type description of the image upload.</textarea></TD>
</TR>-->
<tr><td><Div ID=ImageName>Image preview :</Div></td><td>
<img border="0" width="0" ID="ipreview" src="">
</td></tr>
</form></Table>
 
 
 
 
 
 
<SCRIPT>
//Open window with progress bar.
//pair upload window and progress window (using UploadID).
function ProgressBar(form){
 //check file sizes.
 
 if (checkFileSize()) {
   alert('Upload size is over limit. Please check selected files.')
   return false;
 };
 
  
 //ASP script handling progress window
 var ProgressScript
 ProgressScript = 'progress.asp'
 
 
 //Progress window parameters
 var pp = 'toolbar=no,location=no,directories=no,status=no,menubar=no'
 pp+=',scrollbars=no,resizable=yes,width=350,height=200';
  
 //1. Get unique UploadID
 var UploadID
 UploadID = Math.round(Math.random() * 0x7FFFFFF0)
  
 //2. Add upload ID to form action URL
 var action = form.action;
 if ('' == action) action = ''+document.location;
 action = AddToQuery(action, 'UploadID', UploadID);
 form.action = action
 
 //3. Open progress window with the same UploadID
 var ProgressURL
 ProgressURL = ProgressScript + '?UploadID=' + UploadID 
 
 var v = window.open(ProgressURL,'_blank',pp)
 
 return true;
};
 
//Adds value and its name to querystring
function AddToQuery(q, valname, val){
 if (q.indexOf('?')<0) {
   q += '?'
 } else {
 var pv = q.indexOf(valname+'=');
 if (pv >= 0){
  var amp = q.indexOf('&', pv);
  if (amp<0) {
   q = q.substr(0, pv) 
  } else {
   q = q.substr(0, pv) + q.substr(amp+1) + '&'
  }
 } else {
  if (q.substr(q.length-1)!='?') q += '&'
 };
 };
 q += valname + '=' + val
 return q
};
</SCRIPT> 
 
 
<Script>
//Additional function - dynamic form to add new files at a client side.
 
var nfiles = 3;
//Add two files for upload
//Expand();
function Expand(){
  
  //get an HTML code of a first upload element
  var adh = dfile1.outerHTML;
 
  //replace '1' to nfiles (2, 3, ...)
  adh = adh.replace(/1/g,++nfiles)
  
  //insert the code of a new element before end of div files
  files.insertAdjacentHTML('BeforeEnd',adh);
 
  //clear mask and real value of the element nfiles
  //document.getElementById('maskfile'+nfiles).value=''
  return false;
};
 
</Script>
 
 
<Script>
//Huge-asp upload preview sample
//http://www.motobit.com
 
function isImage(file){
  //Get a file extension
  var ext = file.substr(file.lastIndexOf('.')).toLowerCase()
 
  //Check extension to image types.
  
  return '<%=imageExts%>,'.indexOf(ext+',') >= 0
};
 
var lastfieldname = ''
var filenamechecked = ''
function preview(n) {
  //get current input preview
  var htmlfile = document.getElementById('Image '+n);
  var file = htmlfile.value
 
  //set the size field.
  var himg = document.getElementById('himg'+n);
  if (file.length>0) himg.src = 'file://' + file;
  else { 
    himg.src = ''; 
    document.getElementById('size'+n).innerHTML='-'
  };
  
  if (file.length<=0) return;
 
  //or get get preview for one of form field
  //var file = file_upload.SourceFile1.value
  var ipreview = document.getElementById('ipreview');
  
  //do not check the file more than one.
  if (filenamechecked != htmlfile.value) {
    filenamechecked = htmlfile.value
  } else {
    return true;
  };
 
  if (isImage(file)) {
 
    //Show preview for the image.
    ipreview.src = 'file://' + file
    //alert(file);
    //alert(ipreview.src);
    ipreview.title = 'Image ' + file 
    if (ipreview.width != 300) ipreview.width = 300;
 
    ImageName.innerHTML = 'Image preview<br>(' + htmlfile.name + ')'
  } else {
    //some default image for preview
    ipreview.src = 'res://shdoclc.dll/warning.gif'
 
    alert('Please choose some image file (<%=imageExts%>)');
    
  };
  
  lastfieldname = htmlfile.name
}
 
function himgLoaded(n){
  checkFileSize();
};
 
 
//this function gets a sizes of images,
//write the sizes to HTML form
//counts total size and checks file sizes against a limit
var maxFileSize = <%=maxFileSize%>
var FormSizeLimit = <%=Form.SizeLimit%>
function checkFileSize() {
  var totalSize = 0;
  var htmlSize;
  var overLimit = false;
  for (j = 1; j <= nfiles; j++) {
    var himg = document.getElementById('himg'+j);
    var size = document.getElementById('size'+j);
    var fileSize = himg.fileSize ;
 
    fileSize = parseInt(fileSize);
    
    if (fileSize < 0) {
      size.innerHTML = '-';
    } else {
      htmlSize = formatSize(fileSize);
      if ( fileSize>maxFileSize ) {
        htmlSize += ' (over limit, ' + formatSize(maxFileSize) + ' max)'
        size.style.color = 'red';
        overLimit = true;
      } else {
        size.style.color = '';
      };
      size.innerHTML = htmlSize;
      totalSize += fileSize;
    };//if (fileSize < 0) {
  };//for (j = 1; j <= nfiles; j++)
 
 
  var htotalSize = document.getElementById('totalSize');
  
  if (totalSize > 0){
    htmlSize = formatSize(totalSize);
  } else {
    htmlSize = '-';
  };
  if (totalSize > FormSizeLimit) {
    htotalSize.style.color = 'red';
    htmlSize += ' (over limit, ' + formatSize(FormSizeLimit) + ' max)'
    overLimit = true;
  } else {
    htmlSize += ' (of ' + formatSize(FormSizeLimit) + ' max)'
  };
  htotalSize.innerHTML = htmlSize
  return overLimit;
};
 
function formatSize(size) {
  if (size < 0x100000) {// < 1 MB
    return Math.round(size / 0x400)+"&nbsp;kB"; 
  } else { // > 1 MB
    return (Math.round((size / 0x100000)*10)/10)+"&nbsp;MB";
  }
}
 
 
//window.onerror = donotmsgboxes;
function donotmsgboxes(msg,url,line)
{  // we do not need error messages
  return true
}
 
</Script>
 
 
<br><br>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  
  <TR>
    <TH noWrap align=left width="20%" bgColor=khaki>&nbsp;<A 
      href="http://www.motobit.com/help/scptutl/upload.asp">Huge ASP 
      file upload</A> -  Image upload, combine several upload features.&nbsp;</TH>
    <TD>&nbsp;</TD></TR></TABLE>
 
 
 
 
<HR COLOR=silver Size=1>
<CENTER>
<FONT SIZE=1>&copy; 1996  <%=year(date)%> Antonin Foller, <a href="http://www.motobit.com">Motobit Software</a>, e-mail <A href="mailto:help@pstruh.cz" >help@pstruh.cz</A>
<br>To monitor current running uploads/downloads, see <A Href="http://www.motobit.com/help/iistrace/iis-monitor.asp">IISTracer - IIS real-time monitor</A>.
</FONT>
 
</CENTER>
</Div>
</BODY></HTML>
<%
'This function sends an email message from a local computer, 
' using CDONTS.NewMail or CDO.Message, through IIS SMTP service
' 2006 Antonin Foller, Motobit Software.
Sub SendMailCDO(aTo, Subject, TextBody, byval FileNames, aFrom)
  if not isarray(FileNames) then FileNames = split(FileNames, ",")
 
  Const cdoOutlookExvbsss = 2
  Const cdoIIS = 1
  Const CdoMailFormatMime = 0
  Const cdoSendUsingPort = 2
 
  Dim Message, CDONTS
 
  on error resume next
 
  'Create a new email message
  Set Message = CreateObject("CDONTS.NewMail")
 
  if err = 0 then 'there is CDONTS.NewMail object.
    CDONTS = True
 
    Message.MailFormat = CdoMailFormatMime
 
  else 'use CDO.Message instead
    CDONTS = False
 
    'Create CDO message object
    Set Message = CreateObject("CDO.Message")
 
    'Load IIS configuration
    'Message.Configuration.Load cdoIIS
    'Set configuration fields. 
    With Message.Configuration.Fields
      'Original sender email address 
      .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = aFrom
 
      'SMTP settings - without authentication, using standard port 25 on host smtp
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
 
      'SMTP Authentication
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
 
      .Update
    End With
  end if
  on error goto 0
 
  With Message
    'Set from, to and subject (common properties for newmail and message objects)
    .From = aFrom
    .To = aTo
    .Subject = Subject
 
    'Add attachments
    Dim File 
    For Each File In FileNames
      if CDONTS then
        .AttachFile File
      else
        .AddAttachment File
      end if
    Next
 
    'Set body of the message (different for newmail and message )
    if CDONTS then
      .Body = TextBody
    else
      if instr(1, TextBody, "<body>", 1)>0 then' the TextBody has HTML format.
        .htmlBody = TextBody
      else
        .TextBody = TextBody
      end if
    end if
    
    
    .Send
  End With
End Sub
 
%>

Open in new window

Hello R_Harrison:

Got any idea's on this one yet?
I have been checking around for some other upload to use, and this is still the best
One to use with better support for newer browsers.
So, if you have any idea's to why it is giving the error, I would really love to hear about it.

Thank you again for your time on this one.
Wayne
Sorry, will get back to you tomorrow - with working code!
OK.
Just wanted to make sure that you did not forget about me.
I knew that you would not, but I see that I am in the lead :)
Lets see how long it will last :)
Actually, I would really love to get 1st place, that would be really cool.
At least once.

Have a good one
Wayne
ASKER CERTIFIED SOLUTION
Avatar of R_Harrison
R_Harrison
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I know that feeling.
I would love to be in that situation right now, would love it.
As right this moment, this is all that I have, until my son finishes his next surgery.
(He had to have brain surgery back in Nov.08, and his next surgery is April, 07, 2009)
Until then, this is all that I have to do, is try to get something going on here, and in hopes
That I can make some money on the side doing some bodies site or something.
I did help out a Newspaper with a script.
So, that might lead to something.

Going to test out the script now.
Fingers crossed.

p.s.
I had 1st place a few years ago for 1 month in the "Windows 2000" Category.
So, going to try for it with ASP.
And then maybe when I am really bored. WinXP....

have a good one.
Wayne
You are amazing.
Thank you, thank you, thank you.
Works like a charm!!!!

Thank you so very, very much for all your hard work on this one.
Wayne
You are amazing.
Thank you, thank you, thank you.
Works like a charm!!!!

Thank you so very, very much for all your hard work on this one.
Wayne
I am so very, very sorry.
Please except this question as my sinsere appology to you for not
Upgrading the points and awarding you for all your time, that you spent helping me.
Please forgive me.

https://www.experts-exchange.com/questions/24163611/Question-For-R-Harrison.html


Just add this information to the post

===============
OK, are you running any anti-virus programs.  Specifically Nortons Antivirus?  If so make sure Script Blocking allows the FSO to run as Nortons has been known to see this as a potential threat - may also apply to other AntiVirus programs but I know Nortons can do this.
===============