我正在尝试从 ftp 站点检索文件并将其流式传输到浏览器。
错误是:
警告:ftp_nb_get() 期望参数 2 是字符串,给定资源
我知道这是一种资源,但我该如何解决呢?
if(isset($_GET['filename'])){
$requestfilename = $_GET['filename'];
if($sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP)){
stream_set_write_buffer($sockets[0], 0);
stream_set_timeout($sockets[1], 0);
if($ftp_connection = ftp_connect($ftp_server)){
if (@ftp_login($ftp_connection, $ftp_user, $ftp_pass)) {
if(@ftp_chdir($ftp_connection, $ftp_dir_new)){
if($ret = ftp_nb_get($ftp_connection, $sockets[0], $requestfilename, FTP_BINARY)){
while(ftp_nb_continue($ftp_connection)==FTP_MOREDATA){
$contents = stream_get_contents($sockets[1]);
if($contents !== false) {
echo $contents;
flush();
}
}
if ($ret != FTP_FINISHED) $error[] = 'There was an error downloading the file...';
}else{
$error[] = "Could not ftp_nb_get file from $ftp_server";
}
}else{
$error[] = "Couldn't cd to $ftp_dir_new";
}
} else {
$error[] = "Couldn't connect as $ftp_user";
}
}else{
$error[] = "Couldn't connect to $ftp_server";
}
}else{
$error[] = "Unable to create socket pair";
}
if($sockets){
fclose($sockets[0]);
fclose($sockets[1]);
}
if( ! empty($ftp_connection)) ftp_close($ftp_connection);
}