Hello,
I currently have this setup for a "download a mp3" php page:
<?php
include "class.php";
$account = new account(0);
$id = $_GET['id'];
$u = $_COOKIE['username'];
$a = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE id='$id'"));
$file = $a['actualPath'];
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: audio/mpeg");
header("Content-Transfer-Encoding: binary");
$q = mysql_query("SELECT * FROM boughtItems WHERE username='$u' AND item='$id'");
if(mysql_num_rows($q) >= 1 || $account->isAdmin() || $account->isServiceRep() || $account->isLoggedIn()){
//Allow download
$account->newDownload($id);
readfile($file);
print "You may close this tab/window";
}else{
print "Error: Not authorized";
}
?>
I know that the SQL isn't the best... but let me quickly explain the actual code (functions):
$_COOKIE is a username determining if they are logged in (I know... sessions would likely be better)
$account is a class file (class.php)
isAdmin() checks if admin, returns true/false respectivly
isServiceRep() and isLoggedIn() do the same.
newDownload() is essentially a hit counter.
Then we have the headers, This is where (i think) the issue is.
My headers work in Chrome (I actually get the file) but don't work in:
- Firefox (In fact it grabs the wrong filename, it assumes a folder, eg full/song.mp3 is really full_song.mp3)
- Opera (Shows a 0 byte file, gets filename right though.)
- IE (Same a firefox)
- Safari (Similar to firefox - shows a - instead of a _)
As well, the text doesn't show up (print) with it's current code or echo.
If anyone can help me with these issues, I would greatly appreciate it!
(If you are looking for a URL of the above code: Click Here)
-- Turt2Live