Page 1 of 1

Mp3 Link... Php

PostPosted: 05. June 2012 14:59
by Ruttah
Hello everyone i was hoping someone could help me with some code problems. I'm new to XAMPP and php, still learning my way around.

anyways im making a website for my friend and i need an mp3 download button. Someone was trying to help me with it on another forum but they are not familiar with windows.

When i click on link it just says file not found

Code: Select all
<?php
$mp3 = $_GET['mp3'];
$file = 'C:\xampp\htdocs\JosueWebsite'.$mp3;
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
if ( file_exists($file) ) {
header("Pragma: public");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/mp3");
header('Content-Disposition: attachment; filename="'.$mp3.'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($file));
set_time_limit(0);
@readfile($file) OR die("<html><body OnLoad='javascript: alert('Unable to read file!');history.back();' bgcolor='#F0F0F0'>Unable to read file!</body></html>");
exit;
} else {
die("<html><body OnLoad='javascript: alert('File not found!');history.back();' bgcolor='#F0F0F0'>File not found!</body></html>");
}
?>


and link

Code: Select all
<a href="mp3.php?mp3=GucciWild.mp3">Stupid Wild</a>

Re: Mp3 Link... Php

PostPosted: 05. June 2012 15:07
by Altrea
Hi Ruttah,

Simply output the content of $file right before your file_exists() function.
You will see what's wrong with your code, i think.

best wishes,
Altrea

Re: Mp3 Link... Php

PostPosted: 13. June 2012 22:31
by AndzinSan
This is your error:
Code: Select all
$mp3 = $_GET['mp3'];
$file = 'C:\xampp\htdocs\JosueWebsite'.$mp3;

Code: Select all
<a href="mp3.php?mp3=GucciWild.mp3">Stupid Wild</a>

You miss one backslash :D in $file:
Code: Select all
$file = 'C:\xampp\htdocs\JosueWebsite\'.$mp3;