Solved

upload file from client

Posted on 2002-06-03
10
535 Views
Last Modified: 2012-08-13
how i do asp program that upload file
from cleint "User" to save it the Server
thanx for replay
0
Comment
Question by:hussin14
10 Comments
 
LVL 5

Accepted Solution

by:
kcm76 earned 100 total points
ID: 7050701
try using ftp componet which u can access it from ASP pages. (similar to mail componet).

http://www.visualmart.com/comdcom/ftp.asp

http://www.rainfall.com/coding/kftp.htm

http://www.aspin.com/home/components/internet/ftp
(u can find free ActiveX/Com object here)

ALL THE BEST
KCM.
0
 
LVL 2

Expert Comment

by:chops123
ID: 7050709
Download this very good free component from here:

http://www.coatingtechnology.net/Code-lib/coms/unzipped/ASPSimpleUpload/ASPSimpleUpload.dll

Example is here:

http://www.coatingtechnology.net/Code-lib/coms/unzipped/ASPSimpleUpload/Docs/

When uploading to a specific folder,the permissions to that folder should be set to Read/Write

Rgds
KC
0
 
LVL 2

Expert Comment

by:chops123
ID: 7050717
0
 
LVL 4

Expert Comment

by:Zvika
ID: 7050852
A free and simple to use upload component:
http://www.dundas.com/subFrame.asp?products/asp/upload/index.asp
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7050909
Just to clarify...
The user has to select the file. You can't. But the upload components (of some kind) are needed for the server to accept the uploaded file.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Expert Comment

by:chops123
ID: 7050924
webwoman... just a friendly comment !

whenever i see a comment added by you,i always get reminded of spiderwoman.. donno why ?? ;-)

Rgds
KC
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 7051384
Assuming you have control of the server and the components that get installed, there are a number of really good free Upload components available.  I like ASPSimpleUpload but another good one is ABCUpload, both are free.

If you do not have control of the server, like it's hosted by someone else, chances are good that there is a component already installed.  

I use ASPSimpleUpload at both home and with my hosting company, the upload code looks like this;

<%@ LANGUAGE = "VBScript" %>

<%
Dim upl, NewFileName, theSku

Set upl = Server.CreateObject("ASPSimpleUpload.Upload")

If Len(upl.Form("File1")) > 0 Then
     theFileName = upl.ExtractFileName(upl.Form("File1"))
     fileExt = UCase(upl.ExtractFileExt(theFileName))
     NewFileName = "../images/" & theFileName
          If ((fileExt = ".GIF") Or (fileExt = ".JPG")) Then
               upl.SaveToWeb "File1", NewFileName
               Response.Write "Image Uploaded Successfully"
          Else
               Response.Write("There was an error saving the file to disk.")
          End If
End If
%>

<html>
<head>
<title>Upload Image</title>
<link REL="STYLESHEET" HREF="../class/all.css" TYPE="text/css">
</head>
<body>
<form method="POST" action="imageup.asp" enctype="multipart/form-data">
<table cellpadding=10 cellspacing=0 border=0>
     <tr>
          <td>Select a file to upload: <input type="file" name="File1" size="25"><p><input type="submit" name="submit" value="Upload Now"></td>
     </tr>
</table>
</form>
</body>
</html>

0
 
LVL 1

Expert Comment

by:ksenthilraj
ID: 7053444
Hi,

Use the following class to upload file from client to server..

This code is available in www.asp101.com
1)after save this file in upload.asp
2)include this file in a file where you have to create instance of this class.. upload the file using this properties.
3) Using this class you can get the name of the file uploaded,type of the file uploaded and size of the file also you can get..

<%
Class FileUploader
      Public  Files
      Private mcolFormElem

      Private Sub Class_Initialize()
            Set Files = Server.CreateObject("Scripting.Dictionary")
            Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
      End Sub
      
      Private Sub Class_Terminate()
            If IsObject(Files) Then
                  Files.RemoveAll()
                  Set Files = Nothing
            End If
            If IsObject(mcolFormElem) Then
                  mcolFormElem.RemoveAll()
                  Set mcolFormElem = Nothing
            End If
      End Sub

      Public Property Get Form(sIndex)
            Form = ""
            If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
      End Property

      Public Default Sub Upload()
            Dim biData, sInputName
            Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
            Dim nPosFile, nPosBound

            biData = Request.BinaryRead(Request.TotalBytes)
            nPosBegin = 1
            nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
            
            If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
             
            vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
            nDataBoundPos = InstrB(1, biData, vDataBounds)
            
            Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
                  
                  nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
                  nPos = InstrB(nPos, biData, CByteString("name="))
                  nPosBegin = nPos + 6
                  nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
                  sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                  nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
                  nPosBound = InstrB(nPosEnd, biData, vDataBounds)
                  
                  If nPosFile <> 0 And  nPosFile < nPosBound Then
                        Dim oUploadFile, sFileName
                        Set oUploadFile = New UploadedFile
                        
                        nPosBegin = nPosFile + 10
                        nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
                        sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                        oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))

                        nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
                        nPosBegin = nPos + 14
                        nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
                        
                        oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                        
                        nPosBegin = nPosEnd+4
                        nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
                        oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
                        
                        If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
                  Else
                        nPos = InstrB(nPos, biData, CByteString(Chr(13)))
                        nPosBegin = nPos + 4
                        nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
                        If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                  End If

                  nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
            Loop
      End Sub


      Private Function CByteString(sString)
            Dim nIndex
            For nIndex = 1 to Len(sString)
               CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
            Next
      End Function

      'Byte string to string conversion
      Private Function CWideString(bsString)
            Dim nIndex
            CWideString =""
            For nIndex = 1 to LenB(bsString)
               CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
            Next
      End Function
End Class

Class UploadedFile
      Public ContentType
      Public FileName
      Public FileData
      
      Public Property Get FileSize()
            FileSize = LenB(FileData)
      End Property

      Public Sub SaveToDisk(sPath)
            Dim oFS, oFile
            Dim nIndex
      
            If sPath = "" Or FileName = "" Then Exit Sub
            If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
      
            Set oFS = Server.CreateObject("Scripting.FileSystemObject")
            If Not oFS.FolderExists(sPath) Then Exit Sub
            
            Set oFile = oFS.CreateTextFile(sPath & FileName, True)
            
            For nIndex = 1 to LenB(FileData)
                oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
            Next

            oFile.Close
      End Sub
      
      Public Sub SaveToDatabase(ByRef oField)
            If LenB(FileData) = 0 Then Exit Sub
            
            If IsObject(oField) Then
                  oField.AppendChunk FileData
            End If
      End Sub

End Class
%>
0
 
LVL 1

Expert Comment

by:ksenthilraj
ID: 7053449
Hi,

With out any component, this simple class is much useful for the file upload from client to server using http upload.

After including the class following is the simple method to upload..

Dim Uploader, File
     Set Uploader = New FileUploader
     Uploader.Upload()
       If Uploader.Files.Count = 0

Hope this help..

Cheers..
0
 
LVL 4

Expert Comment

by:Wakie
ID: 9142907
It appears this question has been abandoned.

I will leave a recommendation in the Cleanup topic area that this question will be:

- Question PAQ'd and points points to kcm76 -

Please leave any comments here within the next seven days.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Wakie,
EE Cleanup Volunteer.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now