0
我试图在php下载文件。我使用了codeigniter下载助手和纯php代码读取文件。我可以在浏览器的网络中获取文件的内容,但无法下载。Php/Codeigniter文件下载
当我试图在一个独立的PHP文件中的readfile函数工作。
这是我的dowload文件的代码块。
// codeigniter
$this->load->helper('download');
$data = file_get_contents(base_url("/images/logo.png"));
force_download($decodedFileInfo->fileName, $data);
// php readfile
$file = "./images/logo.png"; //. $decodedFileInfo->fileName;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}else{
var_dump("hst");die;
}
谢谢。
'的file_get_contents(BASE_URL(...))'会做一个HTTP请求到自己的服务器。为什么?为什么你不能完全绕过http层并直接从文件系统获取它?这比FAR更有效率,比强制完整的http往返。 – 2014-11-05 21:22:10