Download a file from FTP server to client machine via website with CodeIgniter

混江龙づ霸主 提交于 2020-01-14 04:27:08

问题


I need download with CodeIgniter. I tried with the force_download function and download function.

With the download function it works, but doesn't permit select the folder for the download. With the force download function the browser downloads an empty file.

$this->load->helper('download');
$path = file_get_contents(base_url()."modulos/".$filename); // get file name
$name = "sample_file.pdf"; // new name for your file

//

force_download($name, $path); // start download

// or

$this->ftp->download($path, '/local/path/to/'.$name);

回答1:


  • $this->ftp->download downloads a file from an FTP server to a web server.
  • force_download downloads a file from the web server to the client.

To download a file from the FTP server all the way to the the client, you have to combine/chain both functions.

$temp_path = $temp_file = tempnam(sys_get_temp_dir(), $name);
$this->ftp->download($path, $temp_path);

$data = file_get_contents($temp_path);
force_download($name, $data);
unlink($temp_path);


来源:https://stackoverflow.com/questions/57878631/download-a-file-from-ftp-server-to-client-machine-via-website-with-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!