通过PHP将文件从FTP传输到客户端

时间:2019-06-28 13:20:36

标签: php ftp

我想知道如何从ftp_fget,ftp_nb_fget转移? 因为当我在输出中仅插入“ ok”时,它是可行的,但是当我从ftp_fget()中插入PHP:// temp的字符串数据时,否,但是程序出现了问题(HTTP错误:ERR_INVALID_RESPONSE)。

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename.'.tar.gz');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . ftp_size($server, $filename)); //Remove
$tempHandle = fopen('php://temp', 'r+'); 
if (@ftp_fget($server, $tempHandle, $filename, FTP_ASCII, 0)) { 
    rewind($tempHandle); 
    echo stream_get_contents($tempHandle);
}

0 个答案:

没有答案