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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.