Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : ASP : ASP 3.0 : Server.MapPath(), ASP 0171 (0x80004005) Signup · Login
Author Thread
Server.MapPath(), ASP 0171 (0x80004005)
Posted in tutorial: Uploading Files to the Server Hard Disk using plain ASP
·  ahmad
User
Joined: 24 Aug 2005
Total Posts: 5
Server.MapPath(), ASP 0171 (0x80004005)
Posted: 24 Aug 2005
----------------------db-multiple-file-to-diskfolder.asp

<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
%>
<%
'Sample file Field-SaveAs.asp
'Store extra upload info to a database
' and file contents to the disk
Server.ScriptTimeout = 5000

'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%


Server.ScriptTimeout = 1000
Form.SizeLimit = 10240*1024'10MB

'{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 VirtualFolder

VirtualFolder = form("foldername")

'Create destination path+filename for the source file.
'Create an URL for image.
Dim DestinationPath, virtDestinationPath
DestinationPath = Server.mapPath(VirtualFolder) & "\" virtDestinationPath = "http://" + Request.ServerVariables("SERVER_NAME") _
+ GetPath(Request.ServerVariables("SCRIPT_NAME") ) _
+ "/" + VirtualFolder + "/"

'Open recordset to store uploaded data
Dim RS: Set RS = OpenUploadRS


Dim FileField
For Each FileField in Form.Files.Items
'Fo each file sent
if len(FileField.FileName)> 0 then 'File is specified.
Dim DestinationFileName

DestinationFileName = DestinationPath & FileField.FileName

'Save file to physical location
FileField.SaveAs DestinationFileName

'Store extra info about upload to database
RS.AddNew
RS("UploadDT") = Now()
RS("Description") = Form("Desc-" & FileField.Name)
RS("SourceFileName") = virtDestinationPath & FileField.FileName
RS("DestPath") = DestinationFileName
RS("DataSize") = FileField.Length
'RS("FileName") = form("FileName")
'...
RS.Update
end if
Next

'What to do with Form("Description")?

'{b}Save file to the destination
'{/b}

' response.write "<Font color=green><br>SourceFile was saved as " & DestinationFileName
' response.write "<br>See ListFiles table in " & Server.MapPath("upload.mdb") & " database.</Font>"

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


----Continue

Users Who Have Visited This Thread In Last 24 Hours
3 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.