Jump to content

[SOLVED] Download not working correctly


peranha

Recommended Posts

Here is the code that I have for my download page. 

 

<?php

error_reporting(E_ALL);
if(isset($_GET['id']))
{

// open connection
$connection1 = mysql_connect($server, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

$id      = $_GET['id'];
$query   = "SELECT name, type, size, path FROM " . $pre . "upload WHERE id = '$id'";
$result  = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $filePath) = mysql_fetch_array($result);

header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");

readfile($filePath);

// close connection
mysql_close($connection1);

exit;
}

?>

<?php
// open connection
$connection = mysql_connect($server, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");


// create query
$query = "SELECT id, name FROM " . $pre . "upload";

// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes

while($row = mysql_fetch_row($result)) {
?>

<a href="download.php?id=<?php echo $row[0];?>"><?php echo $row[1];?></a> <br>

<?PHP

}

}
else {
// no
// print status message
echo "<H1>";
echo "No rows found!";
echo "</H1>";
}

// close connection
mysql_close($connection);
?>

 

I can download the files, but it adds my header information from the website to the file.  It also makes files such as EXE, and others to not work.

 

EX.

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML>

<HEAD>

<TITLE>BSCARDEALERS.COM</TITLE>

<link href="../includes/style.css" rel="stylesheet" type="text/css" />
<script src="includes/functions.js"></script>

</HEAD>

<BODY>





<H1 align=center>You are logged in as <a href=useredit.php><strong>mike</strong></a> with the IP address of <b class=red><strong>127.0.0.1</strong></b>!</H1><BR>
<H1 align=right><a href=admin.php>Admin</a> | <a href=upload.php>Upload Files</a> | <a href=comments.php>Comments</a> | <a href=pmess.php>PM</a> | <a href=home.php>Home</a> | <a href=useredit.php>Personal Info</a> | <a href=logout.php>logout</a></H1>

 

if anyone could help with the script that would be great.

Link to comment
Share on other sites

  • 2 weeks later...
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.