|
| |
|
|
TTTTT
Posts: 66 Joined: 10/14/2004 Status: offline
|
How do I make files downloadable - 10/14/2004 13:20:20
Hi, this is my first post so sorry if I'm doing anything wrong. I'm trying to make files downloadable from my website (which is not online yet). I'm using frontpage 2003 and most of the files are either pdf or compressed avi. If possible could you tell how I would make these files downloadable, although I assume with the pdf that the file wouldn't have to be downloaded but it would just need a link to it? With the avi files I need it to be a sort of click on the name and then it asks you to download the file. Thanks for the help
|
|
|
|
dpf
Posts: 7126 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: How do I make files downloadable - 10/14/2004 13:30:32
simply load the file to your server and on your page..."click here to download my file " and link that text to the file..its that simple
_____________________________
Dan
|
|
|
|
TTTTT
Posts: 66 Joined: 10/14/2004 Status: offline
|
RE: How do I make files downloadable - 10/14/2004 14:13:33
Thanks a lot I want to try out both ways so I can see which one i preffer. But... I dont really know how to put something in a .zip directory. Any chance you could explain in more detail. I dont quite understand what you mean about acrobat, do you recommend I put them in a .zip directory aswell?
|
|
|
|
TTTTT
Posts: 66 Joined: 10/14/2004 Status: offline
|
RE: How do I make files downloadable - 10/14/2004 14:50:37
Thank you all again If I have any other problems while creating my website ill come back here PLUS I just tried to use thezip folder method, I'm using a page template with a title and links and main page, When I click on the link to alf.zip it gets a screen inside the screen which looks like windows explorer. The other method seems to work ok I think I 'll use that
|
|
|
|
TTTTT
Posts: 66 Joined: 10/14/2004 Status: offline
|
RE: How do I make files downloadable - 10/14/2004 16:57:08
The website is in no way online or uploaded to a server I just click on the preview in internet explorer button
|
|
|
|
TTTTT
Posts: 66 Joined: 10/14/2004 Status: offline
|
RE: How do I make files downloadable - 10/15/2004 2:50:16
SO would it be better for me to make the .zip files downloadable rather than just a link to the file?
|
|
|
|
d a v e
Posts: 4179 Joined: 7/24/2002 From: England (but live in Finland now) Status: offline
|
RE: How do I make files downloadable - 10/15/2004 11:19:40
IMO it's better to just link directly to the file and let users left click and open/be prompted for an action or right click and save it, though a zip file may also be a good option.
_____________________________
David Prescott Gekko web design
|
|
|
|
d a v e
Posts: 4179 Joined: 7/24/2002 From: England (but live in Finland now) Status: offline
|
RE: How do I make files downloadable - 10/15/2004 12:02:27
of course it depends which browser you're using - i'm forgetting how that other browser works (IE) ;)
_____________________________
David Prescott Gekko web design
|
|
|
|
jeepless
Posts: 226 Joined: 12/20/2003 From: Smack in the middle of USA Status: offline
|
RE: How do I make files downloadable - 10/16/2004 12:13:27
How do I make files downloadable? Since I see this question a lot, I offer the following two asp scripts that I discovered some time ago (I don't remember where). I've used them since with absolutely no problems, and with a little tweaking (if it's even necessary), you should be able to make them work for you. These scripts will force the download prompt to appear instead of opening the file in the browser, but only when the content-type is pre-defined in the second script. Undefined content-types will still open in the browser. The first script will list all files available for dowload by searching the folder where they are stored:
First, create a new page and give it an .asp extension.
Then design the page how you want it to look (ie, add tables, text, graphics, etc.).
Other than the .asp extension, you can name this page whatever you like.
Then within the html code, add the following to the very top of your page (before the opening html tag):
<%
Dim strThisPage
strThisPage = Request.ServerVariables("SCRIPT_NAME")
strThisPage = Right(strThisPage, Len(strThisPage) - 1)
'****************************************************
' Add the path to the folder that holds your files in the next statement.
'****************************************************
Dim FILE_FOLDER
'Add the path to the folder that holds your files here
FILE_FOLDER = Server.MapPath("./yourfilefolder/") '<----
%>
Now add the following into your html code where you want the actual file names listed (eg, in a table cell):
<%
GetAllFiles
%>
Add the following to the very end of your html code (after the closing html tag):
<%
Sub GetAllFiles()
Dim oFS, oFolder, oFile
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
'Set Folder Object To Proper File Directory
Set oFolder = oFS.getFolder(FILE_FOLDER)
Dim intCounter
Dim FileArray()
intCounter = 0
ReDim Preserve FileArray(oFolder.Files.Count, 4)
For Each oFile in oFolder.Files
strFileName = oFile.Name
strFileType = oFile.Type
strFileSize = oFile.Size
strFilePath = oFile.Path
strFileDtMod = oFile.DateLastModified
FileArray(intCounter, 0) = strFileName
FileArray(intCounter, 1) = "<A class=File HREF=" & Chr(34) & "startDownload.asp?File=" _
& strFilePath & "&Name=" & strFileName & "&Size=" & strFileSize & Chr(34) _
& " onMouseOver=" & Chr(34) & "self.status='" & strFileName & "'; return true;" & Chr(34) _
& " onMouseOut=" & Chr(34) & "self.status=''; return true;" & Chr(34) & ">" & strFileName & "</A>"
FileArray(intCounter, 2) = strFileType
FileArray(intCounter, 3) = strFileSize
'FileArray(intCounter, 4) = strFilePath
FileArray(intCounter, 4) = strFileDtMod
intCounter = (intCounter + 1)
Next
' EchoB("<B>" & oFolder.Files.Count & " Files Available for Download</B>")
intRows = uBound(FileArray, 1)
intCols = uBound(FileArray, 2)
For x = 0 To intRows -1
Echo("<TR>")
For z = 0 To intCols
If z > 0 Then
BuildTableCol(FileArray(x, z))
End IF
Next
Echo("</TR>")
Next
Cleanup oFile
Cleanup oFolder
Cleanup oFS
End Sub
Function Echo(str)
Echo = Response.Write(str & vbCrLf)
End Function
Function EchoB(str)
EchoB = Response.Write(str & "<BR>" & vbCrLf)
End Function
Sub Cleanup(obj)
IF isObject(obj) Then
Set obj = Nothing
End IF
End Sub
Function StripFileName(strFile)
StripFileName = Left(strFile, inStrRev(strFile, "\"))
End Function
Sub BuildTableCol(strData)
Echo("<TD CLASS=DataCol>" & strData & "</TD>")
End Sub
'Not implemented
Sub BuildTableRow(arrData)
Dim intCols
intCols = uBound(arrData)
For y = 0 To intCols
Echo("<TD CLASS=DataCol>" & arrData(y) & "</TD>")
Next
End Sub
%>
Finally, save this page and link to it from your other pages.
The second script will force the file to dowload and prompt the user to save the file to their hard drive. It MUST be used in conjunction with the first script:
Save the following code as a new .asp page and name it "startDownload.asp".
<%
'****************************************************
' This page forces the 'save as file' prompt to prevent files from being opened in the browser.
' It MUST be saved as "startDownload.asp" to work with the first script.
'****************************************************
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = Request.QueryString("File")
strFileSize = Request.QueryString("Size")
strFileName = Request.QueryString("Name")
Response.Clear
'*******************************
' Requires MDAC 2.5 to be stable
' I recommend MDAC 2.6 or 2.7
'*******************************
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFileName, 4))
' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=000" & strFileName
Response.AddHeader "Content-Length", strFileSize
' In a Perfect World, Your Client would also have UTF-8 as the default in their browser
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
For these two scripts to work properly they must be stored in the same file folder. The first script can be embedded in any page you like using any file name you prefer (eg, myfiles.asp). The second script MUST be saved as "startDownload.asp" since the first script specifically calls that page. Then just link to the page that contains the first script (eg, "myfiles.asp) from your other web pages. When the first page (eg, "myfiles.asp") is accessed, the script will display and sort the files in alphabetical order. When a file name on this page is clicked, the browser will open the "save as file" prompt. That's it! You can see the scripts in action by going here: Download Page I can offer some limited help to get these scripts to work for you, if needed. I'm not an asp guru, but I've tinkered with these two scripts enough to make them work in multiple situations. Cheers!
|
|
|
|
Andraw
Posts: 13 Joined: 1/16/2005 Status: offline
|
RE: How do I make files downloadable - 1/17/2005 11:16:19
Hi, jeepless, Your source codes for downloading file is very helpful, thank you very much. I have a question, if I don't want a link, instead, I want to use a button, when use click the button, the download dialog box appear, how can I do it? Please give me some instruction. when I use links: in startDownload.asp file, the querystring variable are: File: C:\Inetpub\wwwroot\test\DownloadAbleFile\reportWord1.doc size: 24064 name: reportWord1.doc But when I use button, they are: File: C:InetpubwwwrootestDownloadAbleFileeportWord1.doc size: 24064 name: reportWord1.doc the backslash is gone, why??????? Andraw
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|