我想从服务器上下载一个文件。
下面是我的控制器代码。
public function download($id)
{
$this->load->helper('url');
$base_url = $this->config->item('base_url');
$base_path = $this->config->item('base_path');
$this->load->helper('download');
$data = file_get_contents( $base_path.'/uploads/'.$id);
$name = $id;
force_download($name, $data);
}
字符串
但是,我得到了一个错误:
file_get_contents(path/filename): failed to open stream: No such file or directory.
型
我该如何解决这个问题?谢谢
这个问题是在路径本身.实际上它不采取文件名与空间之间.对于前.它的工作与文件名xyz现在很好,但不是与文件名ex.尝试xyz.我认为这是因为空间之间的名称.我怎么能解决这个问题?
2条答案
按热度按时间nzkunb0c1#
您可以使用绝对路径到魔术常数__
http://php.net/manual/en/language.constants.predefined.php
字符串
woobm2wo2#
用curl代替。这可能是你的答案。
http://www.technologyworkshops.net/php/how-to-download-and-save-a-file-to-local-path-using-curl-t132.html
在你的助手中添加这个函数,它工作得很好。
由于链接已断开,请在此处输入密码
与您分享一段代码,它将使用curl将文件保存到您的本地目录。
字符串