473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Stop link to mp3 playing it

nathj
938 Expert 512MB
Hi,

I am currently building a site that will have a downloads section on it. This is for members to download recordings of conferences and events. We have the copyright on the recorded material so all is well there.

At resent I am listing the files on the site using the follwoing code:

[html]
<a href="download/audio/filename.mp3" title="download filename">File Description</a>
[/html]

However, in the case of MP£ it plays the file, in the case of PDF it displays the file. This is the correct behaviour for the tag.

The functionality I am after is for the chosen file to be downloaded automatically, not played or displayed but simply downloaded. Is it possible to do this in PHP?

Cheers
nathj
Aug 10 '07 #1
6 1274
nathj
938 Expert 512MB
Hi,

Forget all that for now. I am going to load each mp3 into an m3u file. This can then be donwloaded.

I also plan in time to offer RAM and ASX

Cheers
nathj
Aug 10 '07 #2
Atli
5,058 Expert 4TB
Hi.

You can force the file to be downloaded like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $filename = $_GET['filename'];
  3.  
  4.     if(!file_exists($filename)) {
  5.         die("File does not exist!");
  6.     }
  7.  
  8.     header("Pragma: public");
  9.     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  10.     header("Cache-Control: private",false);
  11.     header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
  12.     header("Content-Transfer-Encoding: binary");
  13.     header("Content-Type: audio/mp3");
  14.     header("Content-Length: ".filesize($filename));
  15.     readfile("$filename");
  16.     exit();
  17. ?>
  18.  
Aug 10 '07 #3
kovik
1,044 Expert 1GB
Another solution would be to zip the files. Save some server space, download time, and automatically cause the file to be downloaded.
Aug 12 '07 #4
Atli
5,058 Expert 4TB
Another solution would be to zip the files. Save some server space, download time, and automatically cause the file to be downloaded.
It would of course solve the download issues, but as far as saving disc space. Mp3 is already highly compressed, it's unlikely that putting it in a zip file would reduce it's size. It may even increse it.
Aug 12 '07 #5
kovik
1,044 Expert 1GB
It would of course solve the download issues, but as far as saving disc space. Mp3 is already highly compressed, it's unlikely that putting it in a zip file would reduce it's size. It may even increse it.
After some testing, the *.zip format shrinks it about 1k and the *.7z format shrinks it about 2k. Hehe, hardly a difference at all.
Aug 12 '07 #6
nathj
938 Expert 512MB
Hi,

Thanks to everyone for the comments and ideas. I have decided that the use of m3u files is the way forward, just as soon as my host enables support of the MIME type.

I do have one further question on this topic that hope you may be able to help with. The downloads section of the website is only available to memebers and I want to log which members download which files. Each download is set under a category, so if I know which files have been downloaded I can recommend future files from the same category when the user logs into the member profile pages.

At present I have an onclick method on the link that calls a java script function:

Expand|Select|Wrap|Line Numbers
  1. function dataUpdate(pnType, pnItem)
  2. {
  3.     GetXmlHttpObject() ; // a udf that I know works as it is used elsewhere
  4.     gcUrl = "../lib/dataupdateAJAX.php?type=" + pnType + "&item=" + pnItem ; 
  5.     goXMLHTTP.onreadystatechange = function()
  6.     {
  7.         if (goXMLHTTP.readyState==4 || goXMLHTTP.readyState=="complete")
  8.         { 
  9.             var lIsDone = true;
  10.         }
  11.     }  ;
  12.     goXMLHTTP.open("GET",gcUrl,true) ;
  13.     goXMLHTTP.send(null) ;
  14. }
  15.  
I have had an alert in the above code so that I know it is being called, however the PHP page that is referenced in the above code does not seem to be getting called.

Here is the php:
[php]
<?php
session_start();

if(!empty($_GET['type']) && !empty($_GET['item']))
{
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/dataobjects.php');
$loDB = new dataObject("database", "user", "password", "host");

$lnUpdateType = $_GET['type'] ;
$lnItem = $_GET['item'] ;
switch($lnUpdateType)
{
case 1: // update the association between leaders and downloads
$lnLeaderID = $_SESSION['userID'] ;
// first check that the leader does not already have the download associated with them, if they do there is no reason to load it again.
$lcCheckSQL = "SELECT a.ID, a.frequency + 1 as newFrequency from leaderdownloadassociation a WHERE a.leaderID = $lnLeaderID AND a.downloadID = $lnItem" ;
$laAssociation = $loDB->queryGetData($lcCheckSQL) ;
if($laAssociation)
{
// update the frequency
$lnFrequency = $laAssociation[0]['newFrequency'] ;
$lcUpdate = "UPDATE leaderdownloadassociation set frequency = $lnFrequency, editdate = now() WHERE a.leaderID = $lnLeaderID AND a.downloadID = $lnItem" ;
$loDB->iQuery($lcUpdate) ;
}
else // first download
{
$lcTableName = "leaderdownloadassociation" ;
$lcFieldList = "leaderID, downloadID, frequency, createdate, editdate" ;
$lcValueList = "$lnLeaderID, $lnDownloadID, 1, now(), now()";
$loDB->queryInsert($lcTableName, $lcFieldList, $lcValueList, false) ;
}
break ;
}
}

?>
[/php]

The idea here is that if there is already a link between a member and a download then the number of times they have downloaded the file is increased and the edit data of the record is updated.

For some reason the code in the PHP does not seem to be executing. I have thrown an echo into the code and it does not display.

I was wondering if anyone could shed any light on this, or suggest an alternative to solution to the problem.

Cheers
nathj
Aug 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: xxdecieverxx | last post by:
Im making a site... i need to know how to make a window... such as jus a normal windo where i can write text on my site and also have a scro bar on it... almost exactly like this window im typing...
6
by: Mark | last post by:
I am designing a game for a forum. When the user has finished playing I need to save their data to a cookie then navigate to a page which holds their score data (I can't have both sets of data on...
8
by: Tim Bücker | last post by:
Following scenario: The user opens a form, a thread is started to play a sound ... public void playSoundUsingThread() { if (File.Exists(fileLocation)) PlaySound(fileLocation, 0, 0); //...
1
by: Russ Green | last post by:
I hav previosuly had VB.NET 2003 Standard installed on my machine and it works great. Yesterday I installed C++.NET 2003 Standard and starting playing with it. Hardly surprisingly it also worked...
2
by: Poly-poly man | last post by:
I am working on a GTK Midi player (timidgtk.sourceforge.net). As you can see, it's just a timidity frontend. With version 0.03, I'm trying to devel it to use SDL_sound to play the midis. First...
6
by: Alan Isaac | last post by:
I'm fairly new to Python and I've lately been running a script at the interpreter while working on it. Sometimes I only want to run the first quarter or half etc. What is the "good" way to do...
2
by: Nehmo | last post by:
On http://sketchup.google.com/gsu5vtviewer.html#id=27 The video for the Rotate Tool lesson works okay when I click on it, but I want to link directly to it. Looking at the source of the page...
4
by: Benzerari | last post by:
Hi All; Please, if any one knows the visual basic code, to be added to a Stop button in order to stop playing some sound of (*.Wav) type. I have achieved to find the code for start playing sound...
13
by: Adhal | last post by:
Hi, How can I stop hotlinking to a specific file, and I want it to redirect it to a PHP link so I can monitor the number of downloads. Here is my site with the download page:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.