⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manual_memory.html

📁 aspupload
💻 HTML
📖 第 1 页 / 共 2 页
字号:
	<P>
	<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=3>
	<TR><TD BGCOLOR="#FFFF00">
	<FONT SIZE="1" FACE="Courier New">

	&lt;HTML><BR>
	&lt;BODY><BR>

	&lt;%<BR>
		Set Upload = Server.CreateObject("Persits.Upload")<P>

		' we use memory uploads, so we must limit file size<BR>
		Upload.SetMaxSize 100000, True<P>

		' Save to memory. Path parameter is omitted<BR>
		Upload.Save<P>

		' Check whether a file was selected<BR>
		Set File = Upload.Files("FILE1")<BR>
		If Not File Is Nothing Then<BR>
		&nbsp;&nbsp;&nbsp;' Obtain file name<BR>
		&nbsp;&nbsp;&nbsp;Filename = file.Filename<P>

		&nbsp;&nbsp;&nbsp;' check if file exists in c:\upload under this name<BR>
		&nbsp;&nbsp;&nbsp;If Upload.FileExists("c:\upload\" & filename ) Then<BR>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "File with this name already exists."<BR>
		&nbsp;&nbsp;&nbsp;Else<BR>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' otherwise save file<BR>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File.SaveAs "c:\upload\" & File.Filename<BR>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "File saved as " & File.Path<BR>
		&nbsp;&nbsp;&nbsp;End If<BR>
		Else ' file not selected<BR>
		&nbsp;&nbsp;&nbsp;Response.Write "File not selected."<BR>
		End If<BR>
		%><BR>

	&lt;/BODY><BR>
	&lt;/HTML>
	</FONT></TD></TR>
	</TABLE>
	<P>
	Click the link below to run this code sample:
	<P>
	<B><A TARGET="_new" HREF="http://localhost/aspupload/03_memory/filename.asp">http://localhost/aspupload/03_memory/filename.asp</A></B>
	&nbsp;<A HREF="javascript:;" OnClick="open('helppopup.html','','width=400,height=400');"><IMG SRC="help.gif" BORDER="0" ALT="Why is this link not working?"></A>

	</BLOCKQUOTE>

	<B><FONT COLOR="#0000A0">Uploading Files to Two Folders</FONT></B>
	<BLOCKQUOTE>
	Using regular uploads, all the files uploaded at once are saved in the same directory, 
	and under their original names. Memory uploads enable you to save
	files individually in any directory and under arbitrary names.
	<P>
	The next code sample enables a user to upload two files. One file
	is saved in the directory "c:\upload\folder1", the other
	in "c:\upload\folder2", both under the name derived from the current session ID.
	<P>
	The file <B>twofolders.asp</B> contains a form with two file items, FILE1 and FILE2.
	This file is not shown here. The corresponding upload script <B>twofolders_upload.asp</B>
	creates two subdirectories and saves FILE1 in Folder1 and FILE2 in Folder2. Both
	files are saved under the same name derived from SessionID and the original extension:
	<P>
	<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=3>
	<TR><TD BGCOLOR="#FFFF00">
	<FONT SIZE="1" FACE="Courier New">
	&lt;HTML><BR>
	&lt;BODY><BR>

	&lt;%<BR>
	Set Upload = Server.CreateObject("Persits.Upload")<P>

	' we use memory uploads, so we must limit file size<BR>
	Upload.SetMaxSize 100000, True<P>

	' Save to memory. Path parameter is omitted<BR>
	Count = Upload.Save<P>

	' Two files must be selected<BR>
	If Count <> 2 Then<BR>
	&nbsp;&nbsp;&nbsp;Response.Write "You must select 2 files."<BR>
	&nbsp;&nbsp;&nbsp;Response.End<BR>
	End If<P>

	' Create two folders, ignore "already exists" error<BR>
	Upload.CreateDirectory "c:\upload\Folder1", True<BR>
	Upload.CreateDirectory "c:\upload\Folder2", True<P>

	' Obtain File objects<BR>
	Set File1 = Upload.Files("FILE1")<BR>
	Set File2 = Upload.Files("FILE2")<P>

	' Build name from session ID<BR>
	Name = Session.SessionID<P>

	' Save<BR>
	File1.SaveAs "c:\upload\Folder1\" & Name & File1.Ext<BR>
	Response.Write "File 1 is saved under " & File1.Path & "&lt;BR>"<P>
	
	File2.SaveAs "c:\upload\Folder2\" & Name & File2.Ext<BR>
	Response.Write "File 2 is saved under " & File2.Path & "&lt;BR><BR>
	%><BR>

	&lt;/BODY><BR>
	&lt;/HTML>
	</FONT></TD></TR>
	</TABLE>
	<P>
	Click the link below to run this code sample:
	<P>
	<B><A TARGET="_new" HREF="http://localhost/aspupload/03_memory/twofolders.asp">http://localhost/aspupload/03_memory/twofolders.asp</A></B>
	&nbsp;<A HREF="javascript:;" OnClick="open('helppopup.html','','width=400,height=400');"><IMG SRC="help.gif" BORDER="0" ALT="Why is this link not working?"></A>
	<P>
	Using uploads to memory to save files in the database is covered in the next chapter.
	
	</BLOCKQUOTE>

	<B><FONT COLOR="#0000A0">Uploading Files to Two Folders (Another Approach)</FONT></B>
	<BLOCKQUOTE>
	To copy and/or rename files, you don't have to use memory uploading.
	The same effect can be achieved using regular (disk) uploading in conjunction
	with the methods <B>File.Copy</B>, <B>File.Move</B> and <B>File.Delete</B>,
	which copy, move and delete an uploaded file, respectively.
	<P>
	The code sample <B>twofoders2_upload.asp</B> does essentially the same 
	as twofolders_upload described above, but without the use of memory uploading:
	<P>

	<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=3>
	<TR><TD BGCOLOR="#FFFF00">
	<FONT SIZE="1" FACE="Courier New">
	&lt;HTML><BR>
	&lt;BODY><BR>

	&lt;%<BR>
	Set Upload = Server.CreateObject("Persits.Upload")<P>

	' Save uploaded files to a temporary folder<BR>
	Count = Upload.Save("c:\upload")<P>

	' Two files must be selected<BR>
	If Count <> 2 Then<BR>
	&nbsp;&nbsp;&nbsp;Response.Write "You must select 2 files."<BR>

	&nbsp;&nbsp;&nbsp;' delete uploaded file, if any<BR>
	&nbsp;&nbsp;&nbsp;For Each File in Upload.Files<BR>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File.Delete<BR>
	&nbsp;&nbsp;&nbsp;Next<BR>
	&nbsp;&nbsp;&nbsp;Response.End<BR>
	End If<P>

	' Create two folders, ignore "already exists" error<BR>
	Upload.CreateDirectory "c:\upload\Folder1", True<BR>
	Upload.CreateDirectory "c:\upload\Folder2", True<P>

	' Obtain File objects<BR>
	Set File1 = Upload.Files("FILE1")<BR>
	Set File2 = Upload.Files("FILE2")<P>

	' Build name from session ID<BR>
	Name = Session.SessionID<P>

	' Copy file 1 to folder 1<BR>
	File1.Copy "c:\upload\Folder1\" & Name & File1.Ext<BR>
	
	' Delete from temp folder<BR>
	File1.Delete<BR>
	Response.Write "File 1 is copied to Folder 1&lt;BR>"<P>
	
	' Copy file 2 to folder 2<BR>
	File2.Copy "c:\upload\Folder2\" & Name & File2.Ext<BR>

	' Delete from temp folder<BR>
	File2.Delete<BR>
	Response.Write "File 2 is copied to Folder 2&lt;BR>"<BR>
	%><BR>

	&lt;/BODY><BR>
	&lt;/HTML><BR>
	</FONT></TD></TR>
	</TABLE>
	<P>
	Click the link below to run this code sample:
	<P>
	<B><A TARGET="_new" HREF="http://localhost/aspupload/03_memory/twofolders2.asp">http://localhost/aspupload/03_memory/twofolders2.asp</A></B>
	&nbsp;<A HREF="javascript:;" OnClick="open('helppopup.html','','width=400,height=400');"><IMG SRC="help.gif" BORDER="0" ALT="Why is this link not working?"></A>
	<P>
	<A HREF="manual_db.html"><IMG BORDER="0" SRC="next.gif" ALIGN="RIGHT" ALT="Chapter 4: Saving Files and/or Filenames in the Database"></A>
	<A HREF="manual_simple.html"><IMG BORDER="0" SRC="previous.gif" ALIGN="RIGHT" ALT="Chapter 2: Uploading Files and Text Items"></A>
	<P>&nbsp;
	</BLOCKQUOTE>
	
	


	</FONT>
	<P>
	<TABLE WIDTH=540 HEIGHT=2 CELLSPACING=0 CELLPADDING=0 BORDER=0>
	<TD BGcolor="#FFCE00"><spacer type=block width=540 height=2></TD>
	</TABLE>
	<P>
	<CENTER>
	<A HREF="index.html"><IMG SRC="logo_small.gif" BORDER=0></A>
	<BR>
	<FONT Face=arial size=1>
	Copyright &copy; 1998 - 2001 <A HREF="http://www.persits.com">Persits Software, Inc.</A><BR>
	All Rights Reserved<BR>
	AspUpload&reg; is a registered trademark of Persits Software, Inc.<BR>
	Questions? Comments? <A HREF="MAILTO:info@aspupload.com">Write us!</A>
	</CENTER>

</TD>
</TABLE>

</BASEFONT>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -