[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1609
  • Last Modified:

Uploading files

Can I upload files using ASP?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 14
  • 14
  • 9
2 Solutions
 
fritz_the_blankCommented:
Yes you can! Here is a comparison of many good, and free code-only solutions (no components required):

http://www.taka.nl/programming/asp/comparing_fileupload.asp

Fritz the Blank
0
 
fritz_the_blankCommented:
If you want to use a component, here are some to consider:

http://aspalliance.com/dundas/default.aspx
http://www.aspupload.com
http://www.softartisans.com/

Fritz the Blank
0
 
alorentzCommented:
If so, you can use ASPSIMPLEUPLOAD and it's free.

Download here:  http://www.aquanet.co.il/vip/download/dialers/
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
alorentzCommented:
ANd here is the code for ASPSIMPLEUPLOAD:

Set upl = Server.CreateObject("ASPSimpleUpload.Upload")
            If Len(upl.Form("File1")) > 0 Then
                  NewFileName = upl.ExtractFileName(upl.Form("File1"))
                  dir = "http://www.yourdomain.com/uploads/" & newfilename
             
                If upl.SaveToWeb("File1", NewFileName) Then
               
                %>
                    File successfully written to the <%=dir%> folder!
                   
                <%
                 session("msg") = "<font color=green><b>Upload Successful!</b></font>"
                 response.redirect "uploadcenter.asp"
                Else
               
                %>
                   There was an error saving the file to disk: <%=dir%>
                <%
                End If
            else
               if Len(upl.Form("File1")) <= 0 then
               %>
                  You have not selected a file to upload!
               <%
               else
               %>
                   Unspecified error!
               <%
               end if
            End If
            
             %>
0
 
fritz_the_blankCommented:
>>If so, you can use ASPSIMPLEUPLOAD and it's free.<<

I have already included that with test comparisons in the link above.

Fritz the Blank
0
 
alorentzCommented:
>>Many people post the question regarding how to upload files....

True, but "knowlton" has been here for quite some time, and I would expect him to know of such things...

No offense "knowlton"
0
 
alorentzCommented:
>>I have already included that with test comparisons in the link above.

Funny, I don't see it in there...
0
 
fritz_the_blankCommented:
Perhaps you didn't take the time to look?

http://www.taka.nl/programming/asp/comparing_fileupload.asp

It is the only component type listed in the comparison test. It is free, but it does require the installation of a component on the server. Oddly enough, it does not perform as well as some of the code-only solutions.

FtB
0
 
alorentzCommented:
ASPSimpleUpload is not listed on that document.

Note, you are causing conflict in numerous posts lately.  Why?
0
 
fritz_the_blankCommented:
Oops, I confused smartupload with ASPSIMPLEUPLOAD -- I am doing too many things at once.


>>Note, you are causing conflict in numerous posts lately.  Why?<<
I have no idea what you are talking about.



Out of the tests, this one looks best:

http://www.freeaspupload.net/freeaspupload/requirements.asp

0
 
Tom KnowltonWeb developerAuthor Commented:
After alorentz's unbelievable remark just now, I definitely want "code-only" solutions.  :)
0
 
alorentzCommented:
>>alorentz's unbelievable remark just now

What might they be?
0
 
Tom KnowltonWeb developerAuthor Commented:
You guys think I offer too many points for easy questions?

I'll have to cut back....my apologies!   :)   <g>
0
 
Tom KnowltonWeb developerAuthor Commented:
The reason I come in here so much is I only have a 10 second memory....due to an accident I suffered as a child.  Any similarity to recent Adam Sandler movies is purely coincidental....

Hi  Fritz, alorentz....have we met?
0
 
alorentzCommented:
I did not say that, nor mentioned your name out side of this questions....however, sometime you can find all your answers on Google.

Like this:

http://www.google.com/search?hl=en&ie=UTF-8&q=ASP+upload+files
0
 
Tom KnowltonWeb developerAuthor Commented:
How do you specify a directory path on a hosted server, exactly?

I decided to go with the following code:

You can see it in action here:

http://www.advercaster.com/upload/uploadform.htm

upload folder contains the following code files:


uploadform.htm:


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
      <TABLE BORDER=0>
      <tr><td><b>Enter your fullname:</b><br><INPUT TYPE=TEXT SIZE=40 NAME="FULLNAME"></td></tr>
      <tr><td><b>Select a file to upload:</b><br><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr>
      <tr><td><b>Save To:</b>&nbsp;&nbsp;
            Disk&nbsp;<INPUT TYPE=RADIO NAME="saveto" value="disk" checked>&nbsp;&nbsp;
            Database&nbsp;<INPUT TYPE=RADIO NAME="saveto" value="database">
      </td></tr>
      <tr><td align="center"><INPUT TYPE=SUBMIT VALUE="Upload!"></td></tr>
      </TABLE>
</FORM>
</BODY>
</HTML>

===============================================

uploadexmple.asp

<%@ Language=VBScript %>
<%Option Explicit%>
<!-- #include file="upload.asp" -->
<%

'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
'         FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
'         FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
'         OR LATER.


' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

'******************************************
' Use [FileUploader object].Form to access
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************
Response.Write "<b>Thank you for your upload " & Uploader.Form("fullname") & "</b><br>"

' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
      Response.Write "File(s) not uploaded."
Else
      ' Loop through the uploaded files
      For Each File In Uploader.Files.Items
            
            ' Check where the user wants to save the file
            If Uploader.Form("saveto") = "disk" Then
      
                  ' Save the file
                  File.SaveToDisk "webroot/upload"
      
            ElseIf Uploader.Form("saveto") = "database" Then
                  
                  ' Open the table you are saving the file to
                  Set RS = Server.CreateObject("ADODB.Recordset")
                  RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2
                  RS.AddNew ' create a new record
                  
                  RS("filename")    = File.FileName
                  RS("filesize")        = File.FileSize
                  RS("contenttype") = File.ContentType
            
                  ' Save the file to the database
                  File.SaveToDatabase RS("filedata")
                  
                  ' Commit the changes and close
                  RS.Update
                  RS.Close
            End If
            
            ' Output the file details to the browser
            Response.Write "File Uploaded: " & File.FileName & "<br>"
            Response.Write "Size: " & File.FileSize & " bytes<br>"
            Response.Write "Type: " & File.ContentType & "<br><br>"
      Next
End If

%>


=====================================================

upload.asp


<%
'***************************************
' File:        Upload.asp
' Author: Jacob "Beezle" Gilley
' Email:  avis7@airmail.net
' Date:   12/07/2000
' Comments: The code for the Upload, CByteString,
'                  CWideString      subroutines was originally
'                  written by Philippe Collignon...or so
'                  he claims. Also, I am not responsible
'                  for any ill effects this script may
'                  cause and provide this script "AS IS".
'                  Enjoy!
'****************************************

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

      'String to byte string conversion
      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
 
Tom KnowltonWeb developerAuthor Commented:
>>>>I did not say that, nor mentioned your name out side of this questions....however, sometime you can find all your answers on Google.


Google?  And deprive you and Fritz of some points?   Never!!!!
0
 
fritz_the_blankCommented:
knowlton--

I believe that you should specify that here:

File.SaveToDisk "webroot/upload"


FtB
0
 
alorentzCommented:
path = server.mappath("somefile.asp")

However, ASPSimpleUpload is free and the code I gave works fine...with no performance issue.

Good luck!
0
 
Tom KnowltonWeb developerAuthor Commented:
Yes...I could Google....but EE does add value to these kinds of inquiries:

1)  Friendly staff (who are NEVER sarcastic....lol)
2)  Keeps track of MY previously asked questions.
3)  Focused on IT
4)  Blah blah blah...the list goes on
5)  Did I mention the Experts are sarcastic?
0
 
Tom KnowltonWeb developerAuthor Commented:
>>>However, ASPSimpleUpload is free and the code I gave works fine...with no performance issue.


Let me take a second look at it.......be right back.

I want EASY EASY EASY.........just a way for someone to get THEIR file onto MY SERVER  (hosted by brinkster.com)
0
 
alorentzCommented:
I don't mean NOT USE EE, just sometimes the answers are readily available.... and we expect to help you with the ones that aren't.

Either way, they are you're points...do what you will with them!
0
 
Tom KnowltonWeb developerAuthor Commented:
knowlton--

I believe that you should specify that here:

File.SaveToDisk "webroot/upload"


FtB


=======================================

I swear I did and it didn't work.  
0
 
Tom KnowltonWeb developerAuthor Commented:
alorentz:

>>>>I don't mean NOT USE EE, just sometimes the answers are readily available.... and we expect to help you with the ones that aren't.

Either way, they are you're points...do what you will with them!

=================

Point taken.

I really appreciate your help (and your patience).

I think the interactivity is also a big reason why I frequent EE.........fast answers (which Google can do) but I can also ask questions of real human beings (which.....Google can't do).
0
 
alorentzCommented:
Any luck with ASPSimpleUpload?
0
 
Tom KnowltonWeb developerAuthor Commented:
alorentz:

Not yet................I was actually trying to get the other DEMO working (last ditch effort):

http://www.robotzgame.com/junk/no_upload.bmp


I expected the file to go HERE....but it did not.......


=============================================


I think I will take a look at ASPSimpleUpload now...............  :(    SIGH
0
 
Tom KnowltonWeb developerAuthor Commented:
alorentz:

Where does the file aspsimpleupload.dll go?

Does it go in my webroot folder on my hosted server?
0
 
alorentzCommented:
I goes where you want to register is from....  System32 folder usually.
0
 
alorentzCommented:
But, the aspsimpleupload.EXE form the link I posted should install everything and be ready to roll.  You just have to run the code I gave.
0
 
alorentzCommented:
Do you control the server that your site is on?  You will need to install the component on the server for it to work.
0
 
Tom KnowltonWeb developerAuthor Commented:
Hmmmmmmmmmm.....I am not sure I am understanding.

You are saying that aspsimpleupload.EXE has to be run on every computer that wants to upload something to my website?


I cannot install applications on my hosted server......brinkster does not allow it.  It is a hosted account, you see.
0
 
alorentzCommented:
>>You are saying that aspsimpleupload.EXE has to be run on every computer that wants to upload something to my website?

No, just on the server.

>brinkster does not allow it.  It is a hosted account, you see.

Then you cannot use this component....and you will need to use the script you tried before.  But, you should contact Brinkster and ask them if they have an upload component installed already, and what it is.
0
 
fritz_the_blankCommented:
Or you could just use one of the ones I suggested above here:

http://www.taka.nl/programming/asp/comparing_fileupload.asp

They do not require that you install any .dll files.

Fritz the Blank
0
 
fritz_the_blankCommented:
>>But, you should contact Brinkster and ask them if they have an upload component installed already, and what it is.<<

alorentz has a good idea here. Brinkster can be very fussy about what works and what doesn't (if you don't put your database in the exact folder they specify, for example, you won't be able to update / add records and etc.).

FtB
0
 
Tom KnowltonWeb developerAuthor Commented:
Thank you both for your comments, you have provided some very good feedback and lots of great options.

You comments lead me to contact Brinkster technical support directly, and ask them about file uploading.  Turns out they have a component that comes with my hosting package that does this.  They also provided sample code which was almost identical to what has been provided here in this question.

Bottom line:  It's working now.  :)
0
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0
 
Tom KnowltonWeb developerAuthor Commented:
Glad to have BEEN helped!

Tom
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 14
  • 14
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now