• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 640
  • Last Modified:

Help with ASPupload rename file code.

I'm trying to rename a file when I upload it using ASP upload, I can't seem to get it to work.
For simplicity I just want the upload file to be called "newname".

here is the code given me by Persits to accomplish this
(http://support.persits.com/show.asp?code=PS02041192)

Method 2: Save to memory, then call SaveAs

<%
Set Upload = Server.CreateObject("Persits.Upload")

' Prevent overwriting
Upload.OverwriteFiles = False

' We use memory uploads, so limit file size
Upload.SetMaxSize 1000000, true

' Save to memory
Upload.Save

' Use session ID as the new file name
NewName = Session.SessionID

For Each File in Upload.Files
   File.SaveAs "c:\upload\" & NewName & File.ext
   Response.Write "New name: " & File.FileName & "<BR>"
Next
%>

Since I don't need to use the sessionid I'm assuming we can leave that part out and use something like:

For Each File in Upload.Files
   File.SaveAs "image_scroller/" & "NewName" & File.ext
   Response.Write "New name: " & File.FileName & "<BR>"
Next

My current code has if/then/else statements set up to check for errors and I'm running into trouble figuring out how to incorporate the new code without effecting these statements. Could someone please take a look at my code below and show me how I make this all work. Thanks a bunch.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- Copyright (c) 2000 Persits Software, Inc.-->
<!-- For more information on AspJpeg, and to download your free eval version-->
<!-- visit http://www.aspupload.com -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>JPEG Upload Script</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
 
<%
 
	Set Upload = Server.CreateObject("Persits.Upload")
	Upload.OverwriteFiles = True
	Upload.SetMaxSize 5000000, True
	Upload.CodePage = 65001
 
	On Error Resume Next	
	Count = Upload.Save(Server.Mappath("scroller_images/"))
 
 
	If Err <> 0 or Count = 0 Then
		
%>
 
<FONT SIZE="3" FACE="Arial" COLOR="#FF0000"><% If Err <> 0 Then Response.Write "An error occurred:" & Err.Description Else Response.Write "Nothing has been uploaded."%></B></FONT>
<P>
<FONT SIZE="2" FACE="Arial"><A HREF="updateimagescroller.asp">Try again</A>.</FONT>
 
<%		
	Else
		On Error Goto 0
		Set File = Upload.Files(1)
		If File.ImageType = "UNKNOWN" Then
			File.Delete
%>
<FONT SIZE="3" FACE="Arial" COLOR="#FF0000">This is not a valid image file.</B></FONT>
<P>
<FONT SIZE="3" FACE="Arial"><A HREF="updateimagescroller.asp">Try again</A>.</FONT>
<%		Else
 
			' Special handling of TIFF since AspUpload cannot extract TIFF dimensions
			if File.ImageType = "TIF" Then
				Set Tiff = Server.CreateObject("Persits.Jpeg")
				Tiff.Open File.Path
				ImageWidth = Tiff.OriginalWidth				
				ImageHeight = Tiff.OriginalHeight
				Tiff.Close
			Else
				ImageWidth = File.ImageWidth
				ImageHeight = File.ImageHeight
			End if
%>
 
<FONT SIZE="2" FACE="Arial">
<B>The following <% = File.ImageType%> image has been uploaded:</B><P>
<TABLE CELLSPACING="0" CELLPADDING="2" BORDER="1">
	<TR><TD><FONT SIZE="2" FACE="Arial"><B>Path:</B></FONT></TD>
	<TD><FONT SIZE="2" FACE="Arial"><% = Server.HTMLEncode(File.OriginalPath) %></FONT></TD></TR>
	<TR><TD><FONT SIZE="2" FACE="Arial"><B>Size:</B></FONT></TD>
	<TD><FONT SIZE="2" FACE="Arial"><% = File.Size %> bytes</FONT></TD></TR>
	<TR><TD><FONT SIZE="2" FACE="Arial"><B>Dimensions:</B></FONT></TD>
	<TD><FONT SIZE="2" FACE="Arial"><% = ImageWidth %> x <% = ImageHeight %> pixels</FONT></TD></TR>
</TABLE>
 
<%
Dim picnumber
picnumber = upload.form("picnumber")
response.write (picnumber)
%>
 
 
<P>
<FORM ACTION="productaddmakethumb.asp" METHOD="GET">
	<INPUT TYPE="HIDDEN" NAME="Path" VALUE="<% = Server.HtmlEncode(File.Path) %>">
	<INPUT TYPE="HIDDEN" NAME="filename" VALUE="<% = Server.HtmlEncode(File.ExtractFileName) %>">
	<INPUT TYPE="HIDDEN" NAME="Height" VALUE="<% = ImageHeight %>">
	<INPUT TYPE="HIDDEN" NAME="Width" VALUE="<% = ImageWidth %>">
	<INPUT TYPE="HIDDEN" NAME="scale" VALUE="50">
	<INPUT TYPE="HIDDEN" NAME="NewWidth" VALUE="250">
	<INPUT TYPE="HIDDEN" NAME="NewHeight" VALUE="100">
	<INPUT TYPE="HIDDEN" NAME="ResizeOption" VALUE="1">
	<INPUT TYPE="HIDDEN" NAME="Quality" VALUE="1">
	<INPUT TYPE="HIDDEN" NAME="Sharpen" VALUE="">
	<INPUT TYPE="HIDDEN" NAME="SharpenValue" VALUE="130">
	<INPUT TYPE="HIDDEN" NAME="Rotate" VALUE="0">
	<INPUT TYPE="SUBMIT" VALUE="Continue...">	
</FORM>
<P>
<IMG SRC="scroller_images/<% = Server.HtmlEncode(File.ExtractFileName) %>">
<P>
<FONT SIZE="2" FACE="Arial"><a href="javascript:history.go(-1)">Go Back</a> </FONT>
 
<%
 
		End If
	End If
%>
</BODY>
</HTML>

Open in new window

0
elliottbenzle
Asked:
elliottbenzle
  • 2
  • 2
1 Solution
 
hieloCommented:
try:
0
 
elliottbenzleAuthor Commented:
here is my code before and my new code That doesn't work:

old:

<%

      Set Upload = Server.CreateObject("Persits.Upload")
      Upload.OverwriteFiles = True
      Upload.SetMaxSize 5000000, True
      Upload.CodePage = 65001

      On Error Resume Next      
      Count = Upload.Save(Server.Mappath("scroller_images/"))


      If Err <> 0 or Count = 0 Then
            
%>

New:

<%

      Set Upload = Server.CreateObject("Persits.Upload")
      Upload.OverwriteFiles = True
      Upload.SetMaxSize 5000000, True
      Upload.CodePage = 65001

      On Error Resume Next      
      Count = Upload.Save(Server.Mappath("scroller_images/"))

       Newname = "newname"
      response.write (newname)
      File.SaveAs "scroller_images/" & newname & File.ext
      Response.Write "New name: " & File.FileName & "<BR>"

      If Err <> 0 or Count = 0 Then
            
%>
0
 
hieloCommented:
I didn't realize it got cut off. Try:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- Copyright (c) 2000 Persits Software, Inc.-->
<!-- For more information on AspJpeg, and to download your free eval version-->
<!-- visit http://www.aspupload.com -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>JPEG Upload Script</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
 
<%
		
On Error Resume Next	
Set Upload = Server.CreateObject("Persits.Upload") 
Upload.CodePage = 65001
' Prevent overwriting 
Upload.OverwriteFiles = True
 
' We use memory uploads, so limit file size 
Upload.SetMaxSize 5000000, True
 
' Save to memory 
Upload.Save 
 
' Use session ID as the new file name 
NewName = "newname" 
 
For Each File in Upload.Files 
   Count = File.SaveAs( Server.MapPath("scroller_images/") & NewName & File.ext ) 
Next 
 
	If Err <> 0 or Count = 0 Then
 
%>
<FONT SIZE="3" FACE="Arial" COLOR="#FF0000"><% If Err <> 0 Then Response.Write "An error occurred:" & Err.Description Else Response.Write "Nothing has been uploaded."%></B></FONT>
<P>
<FONT SIZE="2" FACE="Arial"><A HREF="updateimagescroller.asp">Try again</A>.</FONT>
 
<%		
	Else
		On Error Goto 0
		Set File = Upload.Files(1)
		If File.ImageType = "UNKNOWN" Then
			File.Delete
%>
<FONT SIZE="3" FACE="Arial" COLOR="#FF0000">This is not a valid image file.</B></FONT>
<P>
<FONT SIZE="3" FACE="Arial"><A HREF="updateimagescroller.asp">Try again</A>.</FONT>
<%		Else
 
			' Special handling of TIFF since AspUpload cannot extract TIFF dimensions
			if File.ImageType = "TIF" Then
				Set Tiff = Server.CreateObject("Persits.Jpeg")
				Tiff.Open File.Path
				ImageWidth = Tiff.OriginalWidth				
				ImageHeight = Tiff.OriginalHeight
				Tiff.Close
			Else
				ImageWidth = File.ImageWidth
				ImageHeight = File.ImageHeight
			End if
%>
 
<FONT SIZE="2" FACE="Arial">
<B>The following <% = File.ImageType%> image has been uploaded:</B><P>
<TABLE CELLSPACING="0" CELLPADDING="2" BORDER="1">
	<TR><TD><FONT SIZE="2" FACE="Arial"><B>Path:</B></FONT></TD>
	<TD><FONT SIZE="2" FACE="Arial"><% = Server.HTMLEncode(File.OriginalPath) %></FONT></TD></TR>
	<TR><TD><FONT SIZE="2" FACE="Arial"><B>Size:</B></FONT></TD>
	<TD><FONT SIZE="2" FACE="Arial"><% = File.Size %> bytes</FONT></TD></TR>
	<TR><TD><FONT SIZE="2" FACE="Arial"><B>Dimensions:</B></FONT></TD>
	<TD><FONT SIZE="2" FACE="Arial"><% = ImageWidth %> x <% = ImageHeight %> pixels</FONT></TD></TR>
</TABLE>
 
<%
Dim picnumber
picnumber = upload.form("picnumber")
response.write (picnumber)
%>
 
 
<P>
<FORM ACTION="productaddmakethumb.asp" METHOD="GET">
	<INPUT TYPE="HIDDEN" NAME="Path" VALUE="<% = Server.HtmlEncode(File.Path) %>">
	<INPUT TYPE="HIDDEN" NAME="filename" VALUE="<% = Server.HtmlEncode(File.ExtractFileName) %>">
	<INPUT TYPE="HIDDEN" NAME="Height" VALUE="<% = ImageHeight %>">
	<INPUT TYPE="HIDDEN" NAME="Width" VALUE="<% = ImageWidth %>">
	<INPUT TYPE="HIDDEN" NAME="scale" VALUE="50">
	<INPUT TYPE="HIDDEN" NAME="NewWidth" VALUE="250">
	<INPUT TYPE="HIDDEN" NAME="NewHeight" VALUE="100">
	<INPUT TYPE="HIDDEN" NAME="ResizeOption" VALUE="1">
	<INPUT TYPE="HIDDEN" NAME="Quality" VALUE="1">
	<INPUT TYPE="HIDDEN" NAME="Sharpen" VALUE="">
	<INPUT TYPE="HIDDEN" NAME="SharpenValue" VALUE="130">
	<INPUT TYPE="HIDDEN" NAME="Rotate" VALUE="0">
	<INPUT TYPE="SUBMIT" VALUE="Continue...">	
</FORM>
<P>
<IMG SRC="scroller_images/<% = Server.HtmlEncode(File.ExtractFileName) %>">
<P>
<FONT SIZE="2" FACE="Arial"><a href="javascript:history.go(-1)">Go Back</a> </FONT>
 
<%
 
		End If
	End If
%>
</BODY>
</HTML>

Open in new window

0
 
elliottbenzleAuthor Commented:
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now