问题
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