Solved

Uploading files

Posted on 2004-08-21
38
1,589 Views
Last Modified: 2008-01-09
Can I upload files using ASP?
0
Comment
Question by:knowlton
  • 14
  • 14
  • 9
38 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11861755
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11861767
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
 
LVL 31

Expert Comment

by:alorentz
ID: 11861792
If so, you can use ASPSIMPLEUPLOAD and it's free.

Download here:  http://www.aquanet.co.il/vip/download/dialers/
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11861801
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11861803
>>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
 
LVL 31

Expert Comment

by:alorentz
ID: 11861807
>>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
 
LVL 31

Expert Comment

by:alorentz
ID: 11861811
>>I have already included that with test comparisons in the link above.

Funny, I don't see it in there...
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11861827
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
 
LVL 31

Expert Comment

by:alorentz
ID: 11861841
ASPSimpleUpload is not listed on that document.

Note, you are causing conflict in numerous posts lately.  Why?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11861860
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
 
LVL 5

Author Comment

by:knowlton
ID: 11861861
After alorentz's unbelievable remark just now, I definitely want "code-only" solutions.  :)
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11861864
>>alorentz's unbelievable remark just now

What might they be?
0
 
LVL 5

Author Comment

by:knowlton
ID: 11861933
You guys think I offer too many points for easy questions?

I'll have to cut back....my apologies!   :)   <g>
0
 
LVL 5

Author Comment

by:knowlton
ID: 11861947
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
 
LVL 31

Expert Comment

by:alorentz
ID: 11861951
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
 
LVL 5

Author Comment

by:knowlton
ID: 11861964
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
 
LVL 5

Author Comment

by:knowlton
ID: 11861973
>>>>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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11861978
knowlton--

I believe that you should specify that here:

File.SaveToDisk "webroot/upload"


FtB
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 31

Expert Comment

by:alorentz
ID: 11861980
path = server.mappath("somefile.asp")

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

Good luck!
0
 
LVL 5

Author Comment

by:knowlton
ID: 11861989
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
 
LVL 5

Author Comment

by:knowlton
ID: 11861992
>>>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
 
LVL 31

Expert Comment

by:alorentz
ID: 11861996
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
 
LVL 5

Author Comment

by:knowlton
ID: 11861998
knowlton--

I believe that you should specify that here:

File.SaveToDisk "webroot/upload"


FtB


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

I swear I did and it didn't work.  
0
 
LVL 5

Author Comment

by:knowlton
ID: 11862007
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
 
LVL 31

Expert Comment

by:alorentz
ID: 11862031
Any luck with ASPSimpleUpload?
0
 
LVL 5

Author Comment

by:knowlton
ID: 11862038
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
 
LVL 5

Author Comment

by:knowlton
ID: 11862065
alorentz:

Where does the file aspsimpleupload.dll go?

Does it go in my webroot folder on my hosted server?
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11862074
I goes where you want to register is from....  System32 folder usually.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11862078
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
 
LVL 31

Expert Comment

by:alorentz
ID: 11862084
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
 
LVL 5

Author Comment

by:knowlton
ID: 11862100
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
 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 250 total points
ID: 11862112
>>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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11862117
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
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 250 total points
ID: 11864084
>>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
 
LVL 5

Author Comment

by:knowlton
ID: 11871375
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11871462
Glad to have helped,

FtB
0
 
LVL 5

Author Comment

by:knowlton
ID: 11871503
Glad to have BEEN helped!

Tom
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

24 Experts available now in Live!

Get 1:1 Help Now