Jump to content

Corrupt Download


Ltj_bukem

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/95518-corrupt-download/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.