Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 15-10-2003, 01:57 PM
New kid on the block
 
Join Date: Oct 2003
Location: KL
Posts: 5
Rep Power: 0
mdms is on a distinguished road
Upload photo

how to allow user upload photo via our website? what are the required asp codes needed to put?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 15-10-2003, 03:43 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 93
sufyan is on a distinguished road
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

%>
To use it, simple call the class using:

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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 16-10-2003, 11:24 AM
white_neck's Avatar
Senior Webmaster
 
Join Date: Jan 2003
Location: dreamland
Posts: 240
Rep Power: 73
white_neck is on a distinguished road
Send a message via Yahoo to white_neck
tepat skali...
__________________
^_^ <== stay happy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 15-11-2005, 05:47 PM
BujangMaliLebu's Avatar
Novice Webmaster
 
Join Date: Oct 2005
Location: Sarawak
Posts: 18
Rep Power: 0
BujangMaliLebu is on a distinguished road
Send a message via Yahoo to BujangMaliLebu
Quote:
Originally Posted by white_neck
tepat skali...
cam mana sih....
__________________
cinta dipantai mardeka
http://meligaipengerindu.com/ruai/im...a647355744.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58