This is my down loader controller. First time it works properly. it opens save as popup and able to download required file, But next time it shows direct directory listing.
<?php
class Download extends Controller {
function Download(){
parent::Controller();
$this->load->helper('download');
echo "I am in constructor";
}
function index(){
$file = realpath("download")."\\profile.doc";
echo "I am in index.";
exit;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-开发者_如何学运维Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}else{
// File Not Found
echo "File not found";
}
}
}
?>
You should use the download helper as seen in the user_guide. It deals with this type of situation.
精彩评论