jquickuk Posted March 7, 2008 Share Posted March 7, 2008 Please Help!! I am new to php and mysql. I am uploading files to a mysql database. I have managed to do that with no problems. Now i am trying to write that page that will download to file to be viewed. I can see the list of files in the databse but when i click on any of them it says "Warning: Cannot modify header information" then laods of rubbish: ÐÏࡱá>þÿ ')þÿÿÿ&ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿì¥Á#` 𿱠bjbj5G5G 4W-W-=sÿÿÿÿÿÿ¤’’’’’’’¦J J J Here are the lines that it says are incorrect: header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); echo $content; readfile($filePath); Any help will be appreciated. Thanks John Quote Link to comment Share on other sites More sharing options...
conker87 Posted March 7, 2008 Share Posted March 7, 2008 Can we have the script and the full error? Quote Link to comment Share on other sites More sharing options...
jquickuk Posted March 7, 2008 Author Share Posted March 7, 2008 Yep no probs. The script it: <? if(isset($_GET['id'])) { include 'library/config.php'; include 'library/opendb.php'; $id = $_GET['id']; $query = "SELECT name, type, size, content FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); echo $content; readfile($filePath); include 'library/closedb.php'; exit; } // ?> <html> <head> <title>open the files</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? include 'library/config.php'; include 'library/opendb.php'; $query = "SELECT id, name FROM upload"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?> <a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br> <? } } include 'library/closedb.php'; ?> </body> </html> The full error message is: Warning: Cannot modify header information - headers already sent by (output started at d:\library\opendb.php:11) in d:\download.php on line 12 Warning: Cannot modify header information - headers already sent by (output started at d:\library\opendb.php:11) in d:\download.php on line 13 Warning: Cannot modify header information - headers already sent by (output started at d:\library\opendb.php:11) in d:\download.php on line 14 ÐÏࡱá>þÿ 9;þÿÿÿ8ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿì¥Á#` ø¿- bjbj5G5G .W-W--ÿÿÿÿÿÿ¤¤¤¤¤¤¤¤ÞDŠ Š Š Š ž "…¶Æ L $;h£r*¤ *¤¤ ?” ” ” ¤ ¤ ” ” ” ¤¤” º µ–z’ÇŠ ( ” à $U0…” 8 F” ” ¤¨ 8 ” **~ … """„¦ ä"""¦ ¸ÌÚ¤¤¤¤¤¤ÿÿÿÿ BLAH BLAH BLAH Quote Link to comment Share on other sites More sharing options...
revraz Posted March 7, 2008 Share Posted March 7, 2008 Read the error output started at d:\library\opendb.php:11 Which means you can't set headers after your included file. Quote Link to comment Share on other sites More sharing options...
hamza Posted March 7, 2008 Share Posted March 7, 2008 Sweet and simple problem you have !! Listen one thing never ever echo anything before header In your code just remove echo and you will see your it works HAMZA KHAN 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.