peranha Posted December 10, 2007 Share Posted December 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 10, 2007 Share Posted December 10, 2007 After you send the contents of the download file, you also print out some html stuff... Quote Link to comment Share on other sites More sharing options...
peranha Posted December 10, 2007 Author Share Posted December 10, 2007 The code that is getting added to the top of my pages is the header.php page, which is called before the file is being downloaded. Do you have any suggestions as to how to fix this. Quote Link to comment Share on other sites More sharing options...
peranha Posted December 16, 2007 Author Share Posted December 16, 2007 Anybody got any suggestions?? Quote Link to comment Share on other sites More sharing options...
papaface Posted December 16, 2007 Share Posted December 16, 2007 You're not actually making a connection, you are simply storing the connection in a variable. Try changing all your mysql_querys to include the connection you want to use e.g mysql_select_db($db,$connection1) Quote Link to comment Share on other sites More sharing options...
peranha Posted December 16, 2007 Author Share Posted December 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
peranha Posted December 30, 2007 Author Share Posted December 30, 2007 Anybody have any ideas? 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.