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
https://forums.phpfreaks.com/topic/80944-solved-download-not-working-correctly/
Share on other sites

I am connecting to the database, That is all working, I can upload and download files, but when I download, it adds the header.php page to the top of the item that I downloaded.  If I download a txt file that is.  If I download a EXE, it makes it unusable.

  • 2 weeks later...

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.