GhostCyborg GhostCyborg - 6 months ago 40
SQL Question

Stop Header From Downloading File in PHP

I seem to have a problem in my PHP code, whenever I access the file in my browser, it automatically downloads the file, when it should instead display the file. Here's my code:

$fileID = $_GET['f'];
$con = mysql_connect("localhost","root","password");
if (!$con){
die("Coulnd't connect to serer: ". mysql_error());
$FileID = mysql_query("SELECT FileSRC FROM FileCenter WHERE FileKEY = '$fileID'");
$result = mysql_fetch_array($FileID);
$FMime = checkMime($result['FileSRC']);
if (file_exists($result['FileSRC'])){
$contents = file_get_contents($result['FileSRC']);
header('Content-type: '. $FMime);
echo $contents;


Like you discovered the headers aren't being set because output had already started earlier in the php file.

On the third line you have require("GetMime.php");

The checkMime function in GetMime.php has echo finfo_file($finfo, $fileDES);

You call checkMime before you set the header. You can't echo anything out before setting the headers.