mp3/wav download
mp3/wav download
on my website when songs are uploaded the user can download. i have the download button and currently its linked just to the file so when i click it, it goes mysite/music/song.mp3 instead of the download box thingy that should could up giving the user the option where to save etc like in i.e if you get me
cheers
ash
cheers
ash
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
You can force a download by sending some headers that I always forget. See http://uk.php.net/manual/en/function.header.php
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: mp3/wav download
for in the code section, have a look at the php library there is a function for force download in the files.class.inc.php file
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: mp3/wav download
bowersbros wrote:for in the code section, have a look at the php library there is a function for force download in the files.class.inc.php file
where do i find this sorry?
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
wheres the files.class.inc.php file, i casnt just see 2 links to download?
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
ive got it but i cant find the code to force the download?
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
at the bottom of the files.class.inc.php file there are two functions the send some headers.
Re: mp3/wav download
$ext = end(explode('.', $path)); if (empty($types[$ext]) === false){ return $types[$ext]; } return 'application/octet-stream'; } // recursivly empties a folder and deletes it. public static function rmrf($path){ if (is_dir($path) === false){ return false; } $files = scandir($path); unset($files[0], $files[1]); foreach ($files as $file){ if (is_dir($path . DIRECTORY_SEPARATOR . $file)){ if (count(glob($path . DIRECTORY_SEPARATOR . $file . DIRECTORY_SEPARATOR . '*')) > 0){ self::rmrf($path . DIRECTORY_SEPARATOR . $file); }else{ rmdir($path . DIRECTORY_SEPARATOR . $file); } }else{ unlink($path . DIRECTORY_SEPARATOR . $file); } } rmdir($path); return true; } } ?>?/
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
public static function force_download($path){ if (file_exists($path) === false){ return false; } header('Content-Type: application/octetstream'); // <-- this is for stupid IE6 header('Content-Type: application/octet-stream'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Length: ' . filesize($path)); // php4 method used here because large files would use a lot or RAM with readfile. $file = fopen($path, 'rb'); while (feof($file) === false){ echo fread($file, 4096); } fclose($file); } // forces the download of raw data. public static function force_download_raw($name, $size, $data){ header('Content-Type: application/octetstream'); // <-- this is for stupid IE6 header('Content-Type: application/octet-stream'); header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=\"{$name}\""); header("Content-Length: {$size}"); echo $data; } } ?>
so how do i use this for how i need it?
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
Well it shows you what headers you need to send and how to read out a file to the browser.
You need to create a php script that handles the downloads
downloads.php
then you link like.
You need to create a php script that handles the downloads
downloads.php
$path = $_GET['path']; header('Content-Type: application/octetstream'); // <-- this is for stupid IE6 header('Content-Type: application/octet-stream'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Length: ' . filesize($path)); // php4 method used here because large files would use a lot or RAM with readfile. $file = fopen($path, 'rb'); while (feof($file) === false){ echo fread($file, 4096); } fclose($file);would be the most basic form.
then you link like.
<a href="download.php?path=folder/file.mp3">download</a>You then need to make sure that people cant use the script to download random files from your server, but I will leave that to you
Re: mp3/wav download
would that work what you posted?
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
Should do.ashwood wrote:would that work what you posted?
But like I said, you need to make sure people cant use it to download random files.
If you store the mp3 info in a database you could use the row id as the $_GET variables, rather than the actual path, and them query the database for the file name.
Re: mp3/wav download
on the download link its like this..
<?php if(isset($_SESSION['login_username'])) { echo "<a href='index.php?act=download?path=music/".$song_url."'><img src='../styles/default/download_small.png' alt='Download' title='Download' /> </a>"; } else echo ""; ?>
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
when i click the download icon.. page doesnt exist and in the url i get
http://aatm-online.co.uk/index.php?act= ... 001835.mp3
http://aatm-online.co.uk/index.php?act= ... 001835.mp3
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
http://aatm-online.co.uk/index.php?act=download?path=music/1001835.mp3
as a URL makes no sense, you want
http://aatm-online.co.uk/index.php?act=download&path=music/1001835.mp3
EDIT: also I like your background
as a URL makes no sense, you want
http://aatm-online.co.uk/index.php?act=download&path=music/1001835.mp3
EDIT: also I like your background
Re: mp3/wav download
thanks what u think of overall design?jacek wrote:
EDIT: also I like your background
and also... yeah that works now thanks
I would put a signature.. BUT, i don't have the time.
Re: mp3/wav download
the block yellow bits on the pages looks a bit cheap compared to the nice icons and other things.ashwood wrote:thanks what u think of overall design?
Overall fairly nice, but could do with a bit more styling.
cool ... cool, cool, cool. (community reference )ashwood wrote:and also... yeah that works now thanks
Re: mp3/wav download
jacek wrote:the block yellow bits on the pages looks a bit cheap compared to the nice icons and other things.ashwood wrote:thanks what u think of overall design?
Overall fairly nice, but could do with a bit more styling.
cool ... cool, cool, cool. (community reference )ashwood wrote:and also... yeah that works now thanks
block yellow?
I would put a signature.. BUT, i don't have the time.