强制在CodeIgniter FTP类中下载文件 [英] Forcing file to download in CodeIgniter FTP class

查看:77
本文介绍了强制在CodeIgniter FTP类中下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CodeIgniter中使用FTP类,它们具有从FTP下载文件的功能,但是,仅将文件下载到服务器本身。我正在尝试直接将其下载到用户。

I am using the FTP class in CodeIgniter, they have a function for downloading the file from the FTP, however, its only to the server itself. I am trying to get it to download straight to the user.

我知道我可以将其保存到服务器,然后强制下载然后删除。但是,如果文件很大且速度很慢,则会有些麻烦。

I know that i could just save it to the server and then force download and then delete. But its a bit of a hassle if the file is large and it would be slow.

所以我想知道这段代码是否存在仅使用force_download的问题CI功能?

So i am wondering from this code, if there is anyway just to use the force_download CI function?

示例;

$this->ftp->download('/public_html/myfile.html', '/local/path/to/myfile.html', 'ascii');

谢谢!

推荐答案

您只需将文件下载到PHP的标准输出流中,而不是像这样下载文件[stream]:

You simply download the file to PHP's standard output stream instead of a file [stream] like so:

<?php

header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="test.txt"');
$this->ftp->download('/public_html/test.txt', 'php://output', 'ascii');

(注意:标头用于强制下载,否则浏览器仅打印内容)

(Note: headers are used to force the download, otherwise the browser would simply print the contents)

不客气!

这篇关于强制在CodeIgniter FTP类中下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆