I've been trying to download a file with the help of the header function, but
<?php
if(isset($_GET['download'])){
echo "OK1";
if(!strstr($_GET['download'], '..')){
echo "OK2";
$bestand = $_GET['download'];
if(file_exists($dir.$bestand)){
echo "OK3";
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$bestand."");
header("Content-Length: ".filesize($dir.$bestand));
readfile($dir.$bestand);
}else{
header("Location: index.php?Pagina=persoonlijke_bestanden&melding=Dit is een ongeldig bestand om te downloaden!");
}
}else{
header("Location: index.php?Pagina=persoonlijke_bestanden&melding=Dit is een ongeldig bestand om te downloaden!");
}
}
?>
doens't not to work. If I delete all 4 header rules (under OK3), then everything will work, and there will be echo't: OK1OK2OK3, Because of that I know the file can be found, so it exists! If I use the 4 header rules in my code, I still get a downloadpopup, but if I download the file and open I get 'corrupt of invalid file'! And I have this problem with all files, excel, word, powerpoint etc.
Notice: I have placed on top of my page ob_start ();, and error reporting is on (all), and I get no error, so there isn't a coding error?