0

Download.php not working..

i was just making a download.php file which accepts the song_id from the url and fetch it from database..

example:

download.php?id=111

this will download the song with id=111 from the database..

but the song is not being downloaded..
no response just blank screen.

the details i am having are

table:

id int(11) not null auto increment
physicalpath varchar(250) not null
FileName varchar(250)

download.php:contents

<?php
if ($id) {
  include "open_db.inc";
  $sql = "SELECT DownloadFile, OriginalFileName FROM songs WHERE id=$id";

  $result = @mysql_query($sql, $db);
  $path = @mysql_result($result, 0, "DownloadFile");
  $name = @mysql_result($result, 0, "OriginalFileName");    
  header("Content-type: audio/mpeg");
  header("Content-Disposition: attachment; filename=$name");
  header("Content-Description: PHP Generated Data");
  echo $path;
}
?>

the open_db.inc: contents

<?php
    $db = mysql_connect("localhost", "DB_USER", "DB_PASSWORD");
    mysql_select_db("DB_NAME", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
?>

Edited by mike_2000_17: Fixed formatting

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by jayesh4414
0
<?php
if ($id) {
include "open_db.inc";
$sql = "SELECT DownloadFile, OriginalFileName FROM songs WHERE id=$id";

$id should be from $_GET

run display errors on your localhost, so that stuff like this will be displayed as an error rather than a blank.

0

Where did you get DownloadFile and OriginalFileName from when it's not even in your table?

You might want to use this query:

"SELECT * FROM songs WHERE id = '$id'";

or

"SELECT physicalpath, FileName FROM songs WHERE id = '$id'";

Also, I'm not sure why you're using @mysql_query for your code when you can do something like this:

$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['physicalpath'];
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.