Ltj_bukem Posted March 10, 2008 Share Posted March 10, 2008 Hi, I have two scripts that are used to download pdfs & mpegs. The script for the pdfs works fine but the mp3 download as corrupted. Here's the pdf script <?php session_start(); if(isset($_GET['id'])) { // if id is set then get the file with the id from database mysql_connect("****", "***", "*****") or die("Error connecting to MySQL: ".mysql_error()); // then select the database mysql_select_db("***") or die("Error selecting database: ".mysql_error()); $id = $_GET['id']; $query = "SELECT id, name, type, size, content, dance, tmp_name " . "FROM download WHERE id = '$id'"; $name = $_GET['name']; $result = mysql_query($query) or die('Error, query failed'); list($id, $name, $type, $size, $content, $dance, $temp) = mysql_fetch_array($result); header('Content-type: application/pdf'); header('Content-Disposition:attachment; filename="'.$name.'"'); readfile("$temp"); } ?> Here's the mp3's <?php session_start(); if(isset($_GET['id'])) { // if id is set then get the file with the id from database mysql_connect("****", "***", "****") or die("Error connecting to MySQL: ".mysql_error()); // then select the database mysql_select_db("****") or die("Error selecting database: ".mysql_error()); $id = $_GET['id']; $query = "SELECT id, name, artist,album,label, type,size, content,tmp_name,catid,price,instrument,description " . "FROM mp3 WHERE id = '$id'"; $name = $_GET['name']; $result = mysql_query($query) or die('Error, query failed'); list($id, $name, $artist,$album,$label, $type,$size, $content,$temp,$catid,$price,$instrument,$description) = mysql_fetch_array($result); header('Content-Disposition:attachment; filename="'.$name.'"'); header('Content-type: audio/mpeg'); header("Content-Length: " . filesize($size)); readfile($temp); exit; } ?> I've basically re-used the first script to make the second, if anyone could help that would be cool. Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.