Mp3 Link... Php

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Mp3 Link... Php

Postby Ruttah » 05. June 2012 14:59

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
$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));
@readfile($file) OR die("<html><body OnLoad='javascript: alert('Unable to read file!');history.back();' bgcolor='#F0F0F0'>Unable to read file!</body></html>");
} 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>
Posts: 1
Joined: 05. June 2012 14:52
Operating System: Windows 7 64bit

Re: Mp3 Link... Php

Postby Altrea » 05. June 2012 15:07

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,
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
AF Moderator
Posts: 9361
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Mp3 Link... Php

Postby AndzinSan » 13. June 2012 22:31

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;
Apache 2.2.22 with mod_autoindex_color, python 2.7.2/diango and PHP 5.3.8
Skilled in HTML, CSS, JS, jQUERY, PHP, MYSQL...
Posts: 15
Joined: 19. May 2012 19:20
Operating System: win7

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 66 guests