I am trying to get my site to download mp3 files without having to right click - save as on a link.
I have found this code, which works as long as the file names are short, if they get a bit long it just opens a blank page, can anyone help - <%@Language="VBScript"%>
-
<%Option Explicit%>
-
<%Response.Buffer = True%>
-
<%
-
On Error Resume Next
-
Dim strPath
-
strPath = CStr(Request.QueryString("file"))
-
'-- do some basic error checking for the QueryString
-
If strPath = "" Then
-
Response.Clear
-
Response.Write("No file specified.")
-
Response.End
-
ElseIf InStr(strPath, "..") > 0 Then
-
Response.Clear
-
Response.Write("Illegal folder location.")
-
Response.End
-
ElseIf Len(strPath) > 1024 Then
-
Response.Clear
-
Response.Write("Folder path too long.")
-
Response.End
-
Else
-
Call DownloadFile(strPath)
-
End If
-
-
Private Sub DownloadFile(file)
-
'--declare variables
-
Dim strAbsFile
-
Dim strFileExtension
-
Dim objFSO
-
Dim objFile
-
Dim objStream
-
'-- set absolute file location
-
strAbsFile = Server.MapPath(file)
-
'-- create FSO object to check if file exists and get properties
-
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
-
'-- check to see if the file exists
-
If objFSO.FileExists(strAbsFile) Then
-
Set objFile = objFSO.GetFile(strAbsFile)
-
'-- first clear the response, and then set the appropriate headers
-
Response.Clear
-
'-- the filename you give it will be the one that is shown
-
' to the users by default when they save
-
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
-
Response.AddHeader "Content-Length", objFile.Size
-
Response.ContentType = "application/octet-stream"
-
Set objStream = Server.CreateObject("ADODB.Stream")
-
objStream.Open
-
'-- set as binary
-
objStream.Type = 1
-
Response.CharSet = "UTF-8"
-
'-- load into the stream the file
-
objStream.LoadFromFile(strAbsFile)
-
'-- send the stream in the response
-
Response.BinaryWrite(objStream.Read)
-
objStream.Close
-
Set objStream = Nothing
-
Set objFile = Nothing
-
Else 'objFSO.FileExists(strAbsFile)
-
Response.Clear
-
Response.Write("No such file exists.")
-
End If
-
Set objFSO = Nothing
-
End Sub
-
%>
The link is like this to the download.asp page - <a href="../download.asp?file=/mp3/<%=dlRecordset("filename")%>.mp3" class="downloadtext">
and when it does not work the url is like the following - http://www.yaketyyakallmouth.com/download.asp?file=/mp3/ALTMAN%20-%20%20BRIDE%20AND%20GROOMING%20(LIGHTHEARTED,%20TONGUE%20IN%20CHEEK).mp3
could it be the spaces??? the code replaces the spaces with an underscore when it does save
thanks for any ideas or help
3 6461
I have found the problem, it does not work if there is a comma in the file name, does anyone know a way round this???? I have over 2000 files and lots have commas in the file name
jhardman 3,406
Recognized Expert Specialist @colinod
Write a script to rename them. There should be no commas in file names regardless...
Jared
thats what i thought thanks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dave |
last post by:
Hi Everyone,
I was wondering if anyone has ever successfully used SA-FileUp's download
feature. I am being forced to change from
"ASPSmartUpload" as the server I am moving everything to is using SAFileUp
version 3.2.
I ran through their documentation and found a section called "secure
download", unfortunately, their examples do not work
at all!
On Netscape 7, the file "pretends" to download (after changing the file
|
by: chon |
last post by:
I have an ASP page that is sent a file location as a parameter. It opens
this file, loads the ADODB.Stream object and does a binary write to the page
forcing the download dialog to appear. This all works fine. If the user
selects "Open" or "Cancel", the window closes, which is the desired behavior.
If they select "Save", the location dialog shows up, they save the file and
the window remains open. I've tried a number of things to get...
|
by: Chuck Anderson |
last post by:
I am writing a Php script to run on my home PC (Windows) that downloads
an Apache access log file and inserts new entries into a database.. The
only way I can access these log files is through a cPanel URL that
delivers a gzipped copy of the log file with all entires for the current
month (up to the current date and time).
I want to run this script once a day (at night) and would like to
download the gzipped file by resuming from where...
|
by: Owen Jenkins |
last post by:
I've been using Dev's fantastic InetTransferLib to upload and download
files via ftp. Now I'm using the http procedures to have my application
download zip files from my website. Although the download process works
OK, it adds a few bytes to the file during the download, so a 46k file
becomes 52k. I can still open the file using Winzip, but cannot open it
using my active X extraction system (ActiveXZip from www.hdse.com). I
get an error...
|
by: Owen Jenkins |
last post by:
Reposting this message from last week since I have not had a reply so
far. Hopefully someone will have an idea?
---
I've been using Dev's fantastic InetTransferLib to upload and download
files via ftp. Now I'm using the http procedures to have my application
download zip files from my website. Although the download process works
OK, it adds a few bytes to the file during the download, so a 46k file
becomes 52k. I can still open the file...
| |
by: Sleepy |
last post by:
I am wanting to allow a client to download a file from a web server and save it on their local PC. The only way that I have found to do this is to use HTTP headers. I am using the code shown below (which I have copied with some variable name changes) from a book on ASP.NET programming. This code sits in the Page_Load event of a file called 'Download.aspx'. In order to send a file to the client, this page is called from another page (using...
|
by: hoenes1 |
last post by:
Hi,
in my ASP.NET App, I have a list of files which the user can download
on click (using Response.BinaryWrite()). the problem is, that once a
download has started, the user can't navigate in the window because
the response is sending the file and so no new requests can be made.
what possibilities do i have to make the client able to browse other
pages in my app while downloading a file?
Thanks in advance.
|
by: Nathan Sokalski |
last post by:
I want to give visitors to my site the option of downloading a generated
..txt file by clicking a button. I know how to generate text files, but how
do I cause the browser to pop up one of those dialog boxes that says
something like "Do you want to download FILEX.txt?" I want the user to be
able to download the file rather than have the file displayed in the
browser, because the file will include some characters such as tabs and
commas....
|
by: axelman |
last post by:
Hi guys,
I'm using Classic ASP, IIS6, IE 7, FF 3
I've developed a vb script to downloand files hosted in my server (zip, doc,
pdf, jpg, xls, et. etc.) it's very straight forward and there's a lot of
information around the web, however when it comes to dowload files from a
remote server (NOT hosted in my server) there is no information :-(, the
idea is to have an Access DB that stores the full url...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script.
What You Need
Any recent...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |