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>");
?>

Recommended Answers

All 4 Replies

can anyone suggest me anything??

<?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.

Member Avatar for deleted1234

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'];

thanks buddy...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.