I don't know how to upload any file from client site to server and setting the file entry in data base. If anybody knows please tell me how to code it
Printable View
I don't know how to upload any file from client site to server and setting the file entry in data base. If anybody knows please tell me how to code it
You need a third party component.
you can use one of the free ones.
http://www.aspsmart.com
look at their aspsmartupload
It comes with examples and everything.
Actually you can do this wihtout an component, I've done it many times and it works excellent! You'll find VBScript code for this here:
http://www.asptoday.com/content/arti...CaTlg27dSP4cCa
This is very useful, when many webhosting-services does not have any upload-component.
You need a subscription to view that article...
Not everybody has a subscription to this site, anyone has this code, or a look-a-like in its possesion?
Hi again, yes I know that you must be a subscriber, but I thought that maybe some of you was, but ok...I've built an VBscript class to be used from ASP (which means that it must be run under win2k with IIS5).
this script is somehow a bit special for my needs, cause it creates folders if they dont exists, but you can feel free to modify it yourself.Code:<%
'###################################### NEW CLASS #############################################
class clsUploadFile
private byteCount
private binRead
private Function getByteString(StringStr)
dim i
dim char
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
'-----------------------------------------------------------------
private Function getString(StringBin)
dim intCount
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
'-----------------------------------------------------------------
public function getValFromBin(compStr, delimiter)
dim namePosStart
dim namePosEnd
dim nameByteLen
dim strTmp 'as string
dim blnUseFix 'as boolean
blnUseFix = false
if delimiter= "" then
delimiter = "-" 'chr(10)
blnUseFix = true
end if
namePosStart = InstrB(1,binRead,getByteString(compStr)) + len(compStr) + 1
namePosEnd = InstrB(namePosStart,binRead,getByteString(delimiter))
nameByteLen = namePosEnd - namePosStart
strTmp = getString(MidB(binRead,namePosStart,nameByteLen))
if blnUseFix = true then
'special fix to read from post
strTmp = replace(strTmp, chr(13), "|")
strTmp = replace(left(strTmp, 3), "|", "") &right(strTmp, len(strTmp)-3)
strTmp = left(strTmp, instr(strTmp, "|")-1)
strTmp = replace(strTmp, chr(10), "")
end if
getValFromBin = strTmp
end function
'-----------------------------------------------------------------
public sub initialize()
byteCount = Request.TotalBytes
binRead = Request.BinaryRead(byteCount)
end sub
'-----------------------------------------------------------------
public function strGetObjName()
strGetObjName = getValFromBin ("name=", chr(34))
end function
'-----------------------------------------------------------------
public function strGetFileName()
strGetFileName = getValFromBin("filename=", chr(34))
strGetFileName = mid(strGetFileName,InStrRev(strGetFileName, "\") + 1, len(strGetFileName))
end function
'-----------------------------------------------------------------
public function strGetContentType()
strGetContentType = getValFromBin("Content-Type:", chr(13))
end function
'-----------------------------------------------------------------
public sub saveFile(strPath, strFile)
dim boundary
dim posBeg
dim posEnd
dim objValue
dim Value
dim scriptobject
dim myfile
dim i
boundary = MidB(binRead,1,InstrB(1,binRead,getByteString(chr(13)))-1)
PosBeg = InstrB(1,binRead,getByteString("Content-Type:")) + 14
PosEnd = InstrB(PosBeg,binRead,getByteString(chr(13)))
PosBeg = PosEnd + 4
PosEnd = InstrB(PosBeg,binRead,boundary)-2
objValue = MidB(binRead,PosBeg,PosEnd-PosBeg)
value = objValue
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
call checkFolderAndCreate(strPath)
Set MyFile = ScriptObject.CreateTextFile(strPath &strFile)
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close
end sub
'-----------------------------------------------------------------
private sub checkFolderAndCreate(strPath)
if blnCheckFolder(strPath) = false then
createFolder(strPath)
end if
end sub
'-----------------------------------------------------------------
private function blnCheckFolder(strPath)
dim objFSO 'as scripting.filesystemobject
set objFSO = server.CreateObject("scripting.filesystemobject")
if objFSO.FolderExists(strPath) = true then
blnCheckFolder = true
else
blnCheckFolder = false
end if
set objFSO = nothing
end function
'-----------------------------------------------------------------
private sub createFolder(strPath)
dim objFSO 'as scripting.filesystemobject
set objFSO = server.CreateObject("scripting.filesystemobject")
objFSO.createFolder(strPath)
set objFSO = nothing
end sub
'-----------------------------------------------------------------
end class
%>
When you want to upload a file to the server, all you have to do is to first call "initialize" and then call "saveFile(strPath, strFile)", where strPath is the path where you want the file to be saved, and file is the filename.
If you want to get other value from the form (like textareas, radios etc) you use the "getValFromBin("txtBox","")" function, where the first param. is the name of the item and the second param is left empty (its used for other purposes inside the class).
To get the filename from the uploaded file you use the property "strGetFileName".
An example on how the ASP-file can look like:
...and the html-file should look something like this:Code:<%
'dont forget to include the classFile
%>
<!--#include virtual="classFile.asp"-->
<%
dim intTypesID 'as integer
dim strPath 'as string
dim strFile 'as string
dim clsUploadFileRef
set clsUploadFileRef = new clsUploadFile
call clsUploadFileRef.initialize
'gets a value form the hidden named "itemName"
intTypesID = clsUploadFileRef.getValFromBin("itemName", "")
'specify the path
strPath = "/images/"
'get the filename
strFile = clsUploadFileRef.strGetFileName
'save the file
call clsUploadFileRef.saveFile(server.MapPath(strPath) &"\", strFile)
set clsUploadFileRef = nothing
%>
I hope this solves your problems!Code:<form action="nextPage.asp" method="post" ENCTYPE="multipart/form-data">
<input type="file" name="strFile">
<input type="hidden" name="itemName" value="1">
<input type="submit" value="Next">
</form>
_________________________________________
Fredrik Klarqvist
<a href="mailto:[email protected]@spray.se</a>