There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
black screen blue screen blue screen of death boot computer connection crash css dell display driver drivers error excel firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem ram router slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
How to give visitors option to download zipped files?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
conlieu's Avatar
Junior Member with 17 posts.
 
Join Date: Mar 2003
Location: Harvest, Alabama
28-Jan-2004, 08:51 PM #1
Question How to give visitors option to download zipped files?
Hi everyone,

It's been awhile since I've been here. Been tooooo busy.

Anyway, I hope I can find some help with all the knowledge on this site. I am wanting to add a page to one of my websites, where I can password protect access to the page and have zipped files on the page for the visitor to download, ie. ebooks, programs, etc.


I use Dreamweaver MX to build my web pages. (Self taught webby)

Any help would be GREATLY appreciated, can't seem to do a "search" anywhere and find the info. Thanks so much...
cj_white's Avatar
Senior Member with 335 posts.
 
Join Date: Oct 2001
28-Jan-2004, 10:20 PM #2
its just like them downloading anything else. you just need to create a link to the file and when they click it it will ask if they want to open it or save it.

as for the password protection you will need to learn some programming like php, asp, etc. i would recommend php because its free and there are tons of resources for it. you can set up a javascript login but someone can view the code and get your password.
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
29-Jan-2004, 01:12 AM #3
Well lets look at the possibilities.

First, theres asp, you would need to have create an asp uploader for the page they will download from links you (or they)upload.
there are 4 ASP pages to accomplish this, and you require a server that supports ASP uplaods as well.
The first page to create would be called insert.htm, and it would be a simple page to upload files to the database.
The page could be as simple as this:
PHP Code:
<!-- insert.htm -->
<
html>
<
head>
    <
title>Inserts Images into Database</title>
    <
style>
        
bodyinput font-family:verdana,arialfont-size:10pt; }
    </
style>
</
head>
<
body>
    
<
p align="center"> <b><font color="#0000FF">While here you will be Inserting Data 
  into Database
</font></b><br>
  <
br>
  <
font color="#FF0000"><strong>DO NOT upload full programs to this server!!</strong></font></p>
<
p align="center">Acceptable files are zippedimages (all typesdocumentsscripts 
  etc
. <a href="../members/secure_download.asp"><br>To see all data click here</a></p>
<
div align="left"></div>
<
table border="0" align="center">
  <
tr
    <
form method="POST" enctype="multipart/form-data" action="insert.asp">
      <
td width="102">First Name :</td>
      <
td width="1"><br> </td>
      <
td width="390"><input type="text" name="fname" size="20" value="First Name"></td>
      <
tr
        <
td>Last Name :</td>
        <
td>&nbsp;</td>
        <
td><input type="text" name="lname" size="20" value="Last Name"></td>
      </
tr>
      <
tr
          <
td>Member Number:</td>
        <
td>&nbsp;</td>
        <
td><input type="text" name="memnum" size="20" value="Your Member #"></td>
      </
tr>
      <
tr
        <
td>File :</td>
        <
td>&nbsp;</td>
        <
td><input type="file" name="file" size="40"> </td>
      </
tr>
      <
tr
        <
td>&nbsp;</td>
        <
td>&nbsp;</td>
        <
td><input name="submit" type="submit" value="Submit"> </td>
      </
tr>
      <
tr
    </
form>
  </
tr>
</
table>

</
body>
</
html
The next page you would need to create should be called Loader.asp This pages function is to check the file type and size uploaded to ensure it is legal data (set by you). The code would be this:
(sorry, I have to use php links because there is no asp code insert in this forum)
PHP Code:
<%
    
' -- Loader.asp --
    ' 
-- version 1.5.2
    
' -- last updated 12/5/2002
    ' 
Class for handling binary uploads
    
    
Class Loader
        
Private dict
        
        
Private Sub Class_Initialize
            Set dict 
Server.CreateObject("Scripting.Dictionary")
        
End Sub
        
        
Private Sub Class_Terminate
            
If IsObject(intDictThen
                intDict
.RemoveAll
                Set intDict 
Nothing
            End 
If
            If 
IsObject(dictThen
                dict
.RemoveAll
                Set dict 
Nothing
            End 
If
        
End Sub

        
Public Property Get Count
            Count 
dict.Count
        End Property

        
Public Sub Initialize
            
If Request.TotalBytes 0 Then
                Dim binData
                    binData 
Request.BinaryRead(Request.TotalBytes)
                    
getData binData
            End 
If
        
End Sub
        
        
Public Function getFileData(name)
            If 
dict.Exists(nameThen
                getFileData 
dict(name).Item("Value")
                Else
                
getFileData ""
            
End If
        
End Function

        Public Function 
getValue(name)
            
Dim gv
            
If dict.Exists(nameThen
                gv 
CStr(dict(name).Item("Value"))
                
                
gv Left(gv,Len(gv)-2)
                
getValue gv
            
Else
                
getValue ""
            
End If
        
End Function
        
        Public Function 
saveToFile(namepath)
            If 
dict.Exists(nameThen
                Dim temp
                    temp 
dict(name).Item("Value")
                
Dim fso
                    Set fso 
Server.CreateObject("Scripting.FileSystemObject")
                
Dim file
                    Set file 
fso.CreateTextFile(path)
                        For 
tPoint 1 to LenB(temp)
                            
file.Write Chr(AscB(MidB(temp,tPoint,1)))
                        
Next
                        file
.Close
                    saveToFile 
True
            
Else
                    
saveToFile False
            End 
If
        
End Function
        
        Public Function 
getFileName(name)
            If 
dict.Exists(nameThen
                Dim temp
tempPos
                    temp 
dict(name).Item("FileName")
                    
tempPos InStrRev(temp"\")
                    getFileName = Mid(temp, tempPos)
            Else
                getFileName = ""
            End If
        End Function
        
        Public Function getFilePath(name)
            If dict.Exists(name) Then
                Dim temp, tempPos
                    temp = dict(name).Item("
FileName")
                    tempPos = InStrRev(temp, "")
                    getFilePath = Mid(temp, 1, tempPos)
            Else
                getFilePath = ""
            End If
        End Function
        
        Public Function getFilePathComplete(name)
            If dict.Exists(name) Then
                getFilePathComplete = dict(name).Item("
FileName")
            Else
                getFilePathComplete = ""
            End If
        End Function

        Public Function getFileSize(name)
            If dict.Exists(name) Then
                getFileSize = LenB(dict(name).Item("
Value"))
            Else
                getFileSize = 0
            End If
        End Function

        Public Function getFileSizeTranslated(name)
            If dict.Exists(name) Then
                temp = 1 + LenB(dict(name).Item("
Value"))
                    If Len(temp) <= 3 Then
                        getFileSizeTranslated = temp & " 
bytes"
                    ElseIf Len(temp) > 6 Then
                        temp = FormatNumber(((temp / 1024) / 1024), 2)
                        getFileSizeTranslated = temp & " 
megabytes"    
                    Else
                        temp = FormatNumber((temp / 1024), 2)
                        getFileSizeTranslated = temp & " 
kilobytes"
                    End If
            Else
                getFileSizeTranslated = ""
            End If
        End Function
        
        Public Function getContentType(name)
            If dict.Exists(name) Then
                getContentType = dict(name).Item("
ContentType")
            Else
                getContentType = ""
            End If
        End Function

    Private Sub getData(rawData)
        Dim separator 
            separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

        Dim lenSeparator
            lenSeparator = LenB(separator)

        Dim currentPos
            currentPos = 1
        Dim inStrByte
            inStrByte = 1
        Dim value, mValue
        Dim tempValue
            tempValue = ""

        While inStrByte > 0
            inStrByte = InStrB(currentPos, rawData, separator)
            mValue = inStrByte - currentPos

            If mValue > 1 Then
                value = MidB(rawData, currentPos, mValue)

                Dim begPos, endPos, midValue, nValue
                Dim intDict
                    Set intDict = Server.CreateObject("
Scripting.Dictionary")
        
                    begPos = 1 + InStrB(1, value, ChrB(34))
                    endPos = InStrB(begPos + 1, value, ChrB(34))
                    nValue = endPos

                Dim nameN
                    nameN = MidB(value, begPos, endPos - begPos)

                Dim nameValue, isValid
                    isValid = True
                    
                    If InStrB(1, value, stringToByte("
Content-Type")) > 1 Then

                        begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
                        endPos = InStrB(begPos + 1, value, ChrB(34))
    
                        If endPos = 0 Then
                            endPos = begPos + 1
                            isValid = False
                        End If
                        
                        midValue = MidB(value, begPos, endPos - begPos)
                            intDict.Add "
FileName", trim(byteToString(midValue))
                                
                        begPos = 14 + InStrB(endPos + 1, value, stringToByte("
Content-Type:"))
                        endPos = InStrB(begPos, value, ChrB(13))
                        
                        midValue = MidB(value, begPos, endPos - begPos)
                            intDict.Add "
ContentType", trim(byteToString(midValue))
                        
                        begPos = endPos + 4
                        endPos = LenB(value)

                        nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
                    Else
                        nameValue = trim(byteToString(MidB(value, nValue + 5)))
                    End If

                    If isValid = True Then

                        intDict.Add "
Value", nameValue
                        intDict.Add "
Name", nameN

                        dict.Add byteToString(nameN), intDict
                    End If
            End If

            currentPos = lenSeparator + inStrByte
        Wend
    End Sub
    
    End Class

    Private Function stringToByte(toConv)
        Dim tempChar
         For i = 1 to Len(toConv)
             tempChar = Mid(toConv, i, 1)
            stringToByte = stringToByte & chrB(AscB(tempChar))
         Next
    End Function

    Private Function byteToString(toConv)
        For i = 1 to LenB(toConv)
            byteToString = byteToString & chr(AscB(MidB(toConv,i,1))) 
        Next
    End Function
%> 
The next page would need to be be called insert.asphis page is the actual handling page for the uploads code would be this:
PHP Code:
<!--#include file="Loader.asp"-->
<%
    
' -- insert.asp --
    ' 
-- version 1.5.2
    
' -- last updated 12/5/2002
    Response.Buffer = True

    ' 
load object
    Dim load
        Set load 
= new Loader
        
        
' calling initialize method
        load.initialize
        
    ' 
File binary data
    Dim fileData
        fileData 
load.getFileData("file")
    
' File name
    Dim fileName
        fileName = LCase(load.getFileName("file"))
    ' 
File path
    Dim filePath
        filePath 
load.getFilePath("file")
    
' File path complete
    Dim filePathComplete
        filePathComplete = load.getFilePathComplete("file")
    ' 
File size
    Dim fileSize
        fileSize 
load.getFileSize("file")
    
' File size translated
    Dim fileSizeTranslated
        fileSizeTranslated = load.getFileSizeTranslated("file")
    ' 
Content Type
    Dim contentType
        contentType 
load.getContentType("file")
    
' No. of Form elements
    Dim countElements
        countElements = load.Count
    ' 
Value of text input field "fname"
    
Dim fnameInput
        fnameInput 
load.getValue("fname")
    
' Value of text input field "lname"
    Dim lnameInput
        lnameInput = load.getValue("lname")
    ' 
Value of text input field "memnum"
    
Dim member
        member 
load.getValue("memnum")    
        
    
' destroying load object
    Set load = Nothing
%>

<html>
<head>
    <title>Inserts files into Database</title>
    <style>
        body, input, td { font-family:verdana,arial; font-size:10pt; }
    </style>
</head>
<body>
    
<p align="center"> <b>Report for: <font color="#FF0000">Inserted Data</font></b></p>
    
    <table width="700" border="1" align="center" bordercolor="#0000FF">
    <tr>
        <td>File Name</td><td><%= fileName %></td>
    </tr><tr>
        <td>File Path</td><td><%= filePath %></td>
    </tr><tr>
        <td>File Path Complete</td><td><%= filePathComplete %></td>
    </tr><tr>
        <td>File Size</td><td><%= fileSize %></td>
    </tr><tr>
        <td>File Size Translated</td><td><%= fileSizeTranslated %></td>
    </tr><tr>
        <td>Content Type</td><td><%= contentType %></td>
    </tr><tr>
        <td>No. of Form Elements</td><td><%= countElements %></td>
    </tr><tr>
        <td>First Name</td><td><%= fnameInput %></td>
    </tr><tr>
        <td>Last Name</td><td><%= lnameInput %></td>
    </tr>
    <tr>
        
    <td>Member Number</td>
    <td><%= memnum %></td>
    </tr>
    </table>
<p><font color="#FF0000"><strong>File transfer report:</strong></font></p>
<table width="41%" border="1">
  <tr>
    <td width="48%"><font color="#FF0000"><%= fileName %></font></td>
    <td width="52%">
      <%
        ' 
Checking to make sure if file was uploaded
        
If fileSize 0 Then
        
            
' Connection string
            Dim connStr
                connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("databases/upload.mdb")
        
            ' 
Recordset object
            Dim rs
                Set rs 
Server.CreateObject("ADODB.Recordset")
                
                
rs.Open "Files"connStr22
                
                 Adding data
                rs
.AddNew
                    rs
("File Name") = fileName
                    rs
("File Size") = fileSize
                    rs
("File Data").AppendChunk fileData
                    rs
("Content Type") = contentType
                    rs
("First Name") = fnameInput
                    rs
("Last Name") = lnameInput
                    rs
("Member Number") = memnum
                rs
.Update
                
                rs
.Close
                Set rs 
Nothing
                
            Response
.Write "<font color=""green"">File was successfully uploaded...</font>"
        
Else
            
Response.Write "<font color=""brown"">No file was selected for uploading...</font>"
        
End If
            
            
        If 
Err.number <> 0 Then
            Response
.Write "<br><font color=""red"">Something went wrong...</font>"
        
End If
%>
    </
td>
  </
tr>
</
table>
<
p><font color="#FF0000"><strong> </strong></font> </p>
<
p><strong><a href="insert.htm">Add another file?</a> or <a href="/index.asp">Return 
  
To members Area?</a></strong></p>
</
body><body><table border="0" align="center"><tr><form method="POST" enctype="multipart/form-data" action="insert.asp"></form>
  </
tr></table><p style="padding-left:220;">&nbsp;</p>
    
    </
body>
</
html
The next page would be called show.asp and would show the files listed in the database.

PHP Code:
<%
    
' -- show.asp --
    ' 
Generates a list of uploaded files
    
    Response
.Buffer True
    
    
' Connection String
    Dim connStr
        connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("databases/upload.mdb")
%>
<html>
<head>
    <title>Inserts Images into Database</title>
    <style>
        body, input, td { font-family:verdana,arial; font-size:10pt; }
    </style>
</head>
<body>
    <p align="center">
        <b>Showing Binary Data from the Database</b><br>
        <a href="insert.htm">To insert data click here</a>
    </p>
    
    <table width="700" border="1" align="center">
<%
    ' 
Recordset Object
    Dim rs
        Set rs 
Server.CreateObject("ADODB.Recordset")
        
         
opening connection
        rs
.Open "select [ID],[File Name],[File Size],[Content Type],[First Name],[Last Name],[Member Number] from Files order by [ID] desc"connStr34

        
If Not rs.EOF Then
            Response
.Write "<tr><td colspan=""7"" align=""center""><i>"
            
Response.Write "No. of records : " rs.RecordCount
            Response
.Write ", Table : Files</i><br>"
            
Response.Write "</td></tr>"
    
            
While Not rs.EOF
                Response
.Write "<tr><td>"
                
Response.Write rs("ID") & "</td><td>"
                
Response.Write "<a href=""file.asp?ID=" rs("ID") & """>"
                
Response.Write rs("File Name") & "</a></td><td>"
                
Response.Write rs("File Size") & "</td><td>"
                
Response.Write rs("Content Type") & "</td><td>"
                
Response.Write rs("First Name") & "</td><td>"
                
Response.Write rs("Last Name") & "</td><td>"
                
Response.Write rs("Member Number") & "</td><td>"
                
Response.Write "</td></tr>"
                
rs.MoveNext
            Wend
        
Else
            
Response.Write "No Uploads Found"
        
End If
        
        
rs.Close
        Set rs 
Nothing
%>
    </
table>
</
body>
</
html
The last page would be called file.asp. This page retrieves the binary data from the database and the code is:
PHP Code:
<%
    
' -- file.asp --
    ' 
Retrieves binary files from the database
    
    Response
.Buffer True
    
    
' ID of the file to retrieve
    Dim ID
        ID = Request("ID")
        
    If Len(ID) < 1 Then
        ID = 7
    End If
    
    ' 
Connection String
    Dim connStr
        connStr 
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" Server.MapPath("database/upload.mdb")
    
    
' Recordset Object
    Dim rs
        Set rs = Server.CreateObject("ADODB.Recordset")
        
        ' 
opening connection
        rs
.Open "select [File Data],[Content Type] from Files where ID = " IDconnStr24

        
If Not rs.EOF Then
            Response
.ContentType rs("Content Type")
            
Response.BinaryWrite rs("File Data")
        
End If
        
        
        
rs.Close
        Set rs 
Nothing
%> 
You would need to create an access database to store the files in, create a database called uploads
create a table called Files:
create columns (for this example) called:
File Name
File Size
File Data
Content Type
First Name
Last name
Member Number

upload this database to your server and chmod it to read/write Change the database location on all the asp pages to the actual location of your database.



For password protection, you would create a form on an htm page that submits to an asp page or a database.
Have the successful login go to the members download page show.asp, which should have the following code written in it to protect it:
PHP Code:
<%
username Session("username")
'If the username cookie is set, they must have logged in, so get their details from the database or page
if username = "" then
 Response.Redirect("login.asp") '
make this your login page or a redirection page to the login page with an error written on it
end 
if
%> 
note:Place this on the show.asp page for protection before the <head>

Good luck, BTW you can find resources at www.hotscripts.com, there are PHP and ASP examples, code snippets, tutorials etc there.
__________________
Good Luck on your fix

My real hobby..JoyCo
My real Job..(Second Hobby) IAFF Local 1865
Like the sites? My hobby is the one that created them!

Last edited by Sequal7 : 29-Jan-2004 01:20 AM.
AbvAvgUser's Avatar
Distinguished Member with 2,313 posts.
 
Join Date: Oct 2002
Location: Mumbai, India
Experience: Intermediate
29-Jan-2004, 01:20 AM #4
Wow!! What a post!! Taken a lot of trouble for someone else. Keep up the good work!!

By the way, I guess, your hosting service provider (server) should let you password protect any folders. So its as simple as loging in to the Control Panel (or whatever it is called in your case) and changing some settings. I have this facility where I host my sites. So its just one of the basic facilities. User will be asked for a password when he tries to access that folder of the site.

For example http://www.mysite.com/secretfolder . A password needs to be specified to open the folder. Pretty simple.

As regards download, just provide a hyperlink to the zip file and the browser will automatically download it when clicked on the link.
__________________