|
|||
Hi,
To upload using asp, you would need an unload component or if you can't install components, you can also get a COM-less upload class. Code:
<% '*********************************************************************** ' © Sloppycode.net All rights reserved. ' ' This is a standard copyright header for all source code appearing ' at sloppycode.net. This application/class/script may be redistributed, ' as long as the above copyright remains intact. ' Comments to sloppycode@sloppycode.net '*********************************************************************** Class ComLessUpload Private aAllData Private aHdr Private isPosted Private q '--------------------------------------------------------------------------- ' Constructor '--------------------------------------------------------------------------- Private Sub Class_Initialize() If Request.TotalBytes > 0 Then Dim AllDataB, x ' Set flag for posted data isPosted = True ' Retrieve post data q = Chr(34) aAllDataB = Request.BinaryRead(Request.TotalBytes) ' Convert to Ascii from Unicode For x = 1 To LenB(aAllDataB) aAllData = aAllData & Chr(AscB(MidB(aAllDataB, x, 1))) Next ' Retrieve header aHdr = Left(aAllData, InStr(aAllData, vbCrLf) + 1) Else isPosted = False End If End Sub '--------------------------------------------------------------------------- ' Destructor '--------------------------------------------------------------------------- Private Sub Class_Terminate() ' End Sub '--------------------------------------------------------------------------- ' Save with original filename '--------------------------------------------------------------------------- Public Function Save(directory, field, overwrite) 'As Boolean If isPosted Then Dim filename filename = directory & GetFileName(field) SaveFile field,filename,overwrite End If End Function '--------------------------------------------------------------------------- ' Save with different filename '--------------------------------------------------------------------------- Public Function SaveAs(filename, directory, field, overwrite) 'As Boolean If isPosted Then Dim filenameAll filenameAll = directory & filename SaveFile field,filenameAll,overwrite End If End Function '--------------------------------------------------------------------------- ' Look for the specified form field in the data, retrieve its filename '--------------------------------------------------------------------------- Public Function GetFileName(field) If isPosted Then Dim x2, i x = InStr(aAllData, aHdr & "Content-Disposition: form-data; name=" & q & field & q) If x >0 Then x = InStr(x, aAllData, "filename=" & q) x2 = InStr(x, aAllData, vbCrLf) For i = x2 To x Step -1 If Mid(aAllData, i, 1) = "\" Then x = i - 9 Exit For End If Next GetFileName = Mid(aAllData, x + 10, x2 - (x + 11)) End If End If End Function '--------------------------------------------------------------------------- ' Get file data from upload, for a specified field '--------------------------------------------------------------------------- Private Function GetFileData(field) Dim x2 x = InStr(aAllData, aHdr & "Content-Disposition: form-data; name=" & q & field & q) If x > 0 Then x = InStr(x, aAllData, vbCrLf) x = InStr(x + 1, aAllData, vbCrLf) x = InStr(x + 1, aAllData, vbCrLf) + 2 x2 = InStr(x, aAllData, Left(aHdr, Len(aHdr) - 2)) GetFileData = Mid(aAllData, x + 2, x2 - x - 4) End If End Function '--------------------------------------------------------------------------- ' Create an FSO object, save the data to disk '--------------------------------------------------------------------------- Private Sub SaveFile(aField, aFilename, overwrite) 'As Boolean Dim FSO, TS Set FSO = CreateObject("Scripting.FileSystemObject") Set TS = FSO.CreateTextFile(aFilename, overwrite, False) ' final param is unicode TS.Write GetFileData(aField) TS.Close Set TS = Nothing Set FSO = Nothing End Sub End Class %> Code:
<!-- #include virtual="/clsComLessUpload.asp" -->
<%
' Replace the line above with the path to the clsComLessUpload.asp file
Dim upload
Set upload = New ComLessUpload
upload.Save Server.Mappath("/"),"file1",true
upload.SaveAs("myfile", Server.Mappath("/"),"file1", true)
Set Upload = Nothing
%>
<html>
<body>
<form action="example.asp" method="post" enctype="multipart/form-data">
<input name="file1" type="File">
<input type="submit">
</form>
</body>
</html>
|
![]() |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Some Free Photo Editing wanna to share with all | calvynlee | Graphic Design | 1 | 02-11-2006 05:27 AM |
| Snap your photo online for free | Hot-screensaver | Mamak Stall | 1 | 14-10-2005 05:04 PM |
| upload photo | nurulmajdi | Website Programming | 5 | 14-04-2004 11:24 PM |
| Cannot Upload thru ftp ...? | knight | Webmaster Tools | 1 | 26-11-2003 08:18 PM |
| Looking for photo album site | Salva | Mamak Stall | 9 | 27-05-2003 03:52 PM |
All times are GMT +8. The time now is 10:16 AM.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.











Linear Mode

