SolveErrors
ASP

Upload a file to a folder based on a radio box or drop down - Page 4

87 views

Where exactly do you mean Shadow?

Code:
<%
'*******************************************************
'*     ASP 101 Sample Code - http://www.asp101.com/    *
'*                                                     *
'*   This code is made available as a service to our   *
'*      visitors and is provided strictly for the      *
'*               purpose of illustration.              *
'*                                                     *
'*      http://www.asp101.com/samples/license.asp      *
'*                                                     *
'* Please direct all inquiries to [email protected] *
'*******************************************************
%>

<%
' This function takes a filename and returns the appropriate image for
' that file type based on it's extension.  If you pass it "dir", it assumes
' that the corresponding item is a directory and shows the folder icon.
Function ShowImageForType(strName)
	Dim strTemp

	' Set our working string to the one passed in
	strTemp = strName
	
	' If it's not a directory, get the extension and set it to strTemp
	' If it is a directory, then we already have the correct value
	If strTemp <> "dir" Then
		strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
	End If
	
	' Debugging line used to perfect that above string parser
	'Response.Write strTemp
	
	' Set the part of the image file name that's unique to the type of file
	' to it's correct value and set this to strTemp. (yet another use of it!)
	Select Case strTemp
		Case "asp"
			strTemp = "asp"
		Case "dir"
			strTemp = "dir"
		Case "htm", "html"
			strTemp = "htm"
		Case "gif", "jpg"
			strTemp = "img"
		Case "txt"
			strTemp = "txt"
		Case Else
			strTemp = "misc"
	End Select

	' All our logic is done... build the IMG Tag for display to the browser
	' Place it into... where else... strTemp!

	' My images are all GIFs and all start with "dir_" for my own sanity.
	' They end with one of the values set in the select statement above.

	strTemp = ""

	' Set return value and exit function
	ShowImageForType = strTemp
End Function
'That's it for functions on this one!
%>


<%' Now to the Runtime code:
Dim strPath   'Path of directory to show
Dim objFSO    'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem   'Variable used to loop through the contents of the folder

' You could just as easily read this from some sort of input, but I don't
' need you guys and gals roaming around our server so I've hard coded it to
' a directory I set up to illustrate the sample.
' NOTE: As currently implemented, this needs to end with the /
'strPath = "F:\Inetpub\wwwroot\Curriculum Vitae"
strPath = Request("folder")
If Len(strPath)=0 Then
   strPath = "/Curriculum Vitae/"
End If

'Response.Write("current path: " & strPath & "
") ' Create our FSO Set objFSO = Server.CreateObject("Scripting.FileSystemObject") ' Get a handle on our folder ' Set objFolder = objFSO.GetFolder(strPath) Set objFolder = objFSO.GetFolder(Server.MapPath(strPath)) %> Contents of <%= strPath %>

?action=1" enctype="multipart/form-data" method="POST"> Browse to a CV that you wish to upload
Specify CV Applicant Name (note the uploaded file name will appear with this name)
<% ' Create our FSO Set objFSO = Server.CreateObject("Scripting.FileSystemObject") ' Check for Rejected File: Dim strRejectedFile strRejectedFile = Request.QueryString("RejectedFile") If Len(strRejectedFile)>0 Then If objFSO.FileExists(Server.MapPath(strPath & strRejectedFile)) Then objFSO.CopyFile Server.MapPath(strPath & strRejectedFile), Server.MapPath("/RejectedCurriculumVitae/" & strRejectedFile), True objFSO.DeleteFile Server.MapPath(strPath & strRejectedFile) End If End If ' First I deal with any subdirectories. I just display them and when you ' click you go to them via plain HTTP. You might want to loop them back ' through this file once you've set it up to take a path as input. It seems ' like the logical thing to do to me at least! For Each objItem In objFolder.SubFolders ' Deal with the stupid VTI's that keep giving our visitors 404's If InStr(1, objItem, "_vti", 1) = 0 Then %> <% End If Next 'objItem Function CountTotalFiles(objFolder) Dim filesCount, objSubFolder filesCount = objFolder.Files.Count For Each objSubFolder In objFolder.SubFolders filesCount = filesCount + CountTotalFiles(objSubFolder) Next CountTotalFiles = filesCount End Function ' Now that I've done the SubFolders, do the files! For Each objItem In objFolder.Files %> <% Next 'objItem ' All done! Kill off our object variables. Set objItem = Nothing Set objFolder = Nothing Set objFSO = Nothing ' Oops... I almost forgot to close up the table. IE will forgive you, ' but Netscape will catch you on this error - AS IT SHOULD! ' Ok, so I'm a little odd being a Microsoft supporter and yet I still ' use Netscapes's browser... I just like it better... so sue me! ' ' I probably shouldn't say that too loudly... ' ...you never know what the next lawsuit will be! %> <% Dim objUpload If Request("action")="1" Then Set objUpload=New ShadowUpload strPath = objUpload("strPath") If objUpload.GetError<>"" Then Response.Write("sorry, could not upload: "&objUpload.GetError) Else 'Response.Write("found "&objUpload.FileCount&" files...
") For x=0 To objUpload.FileCount-1 'Response.Write("file name: "&objUpload.File(x).FileName&"
") 'Response.Write("file type: "&objUpload.File(x).ContentType&"
") 'Response.Write("file size: "&objUpload.File(x).Size&"
") 'Response.Write("image width: "&objUpload.File(x).ImageWidth&"
") 'Response.Write("image height: "&objUpload.File(x).ImageHeight&"
") If (objUpload.File(x).ImageWidth>200) Or (objUpload.File(x).ImageHeight>200) Then Response.Write("image to big, not saving!") Else Call objUpload.File(x).SaveToDisk(Server.MapPath(strPath), objUpload ("name")) Response.Write("File successfully uploaded!") End If Response.Write("
") Next ' Response.Write("thank you, "&objUpload("name")) End If End If %>
File Name:
No. of CVs
Date Modified: File Type:
<%= ShowImageForType("dir") %> "><%= objItem.Name %> <%=CountTotalFiles(objItem)%> <%= objItem.DateLastModified %>
<%= ShowImageForType(objItem.Name) %> <%= objItem.Name %>   <%= objItem.DateCreated %> <%= objItem.Type %>[Reject CV]

More ASP fixes

IIS: web.config redirect to another url preserving the original one in the address barPagination to display results of MySQLGet actual URL from address bar in Classic ASP on a 404 redirected pageRequested operation requires a current record.asp guestbook w/ textfileguestbook enties - tutorials