问题描述
我目前正在实现一个系统,让用户从ftp下载文件而不需要ftp客户端。我已经开发了一个登录系统,并成功管理列出文件夹中的文件。但是,我打算使用ftp_get以另存为提示进行下载过程。
我提到,但所提出的解决方案并不确凿。
我确实使用了之前论坛主题中的一个建议,但我得到了一个msg执行ftp_get后出现问题。
如果有任何帮助,我将非常感激!谢谢 !
// ------------------------ ---连接到FTP主机------------------------------------------- -
$ conn_id = ftp_connect($ _ COOKIE [process-1])或死(无法连接到FTP服务器);
$ login_result = ftp_login($ conn_id,$ _COOKIE [process-2],$ _COOKIE [process-3]);
// ---------------------------验证FTP Logiin(用户名,密码)--------- ----------------
if(!$ login_result)die(FTP登录失败,联系支持人@ [email protected]);
ftp_pasv($ conn_id,true);
$ current_dir = ftp_pwd($ conn_id);
$ chdir = ftp_chdir($ conn_id,$ _ COOKIE [process-5]);
if(!$ chdir)echoChange Directory failed。Origin =。$ current_dir。 ;目的地:。$ _ COOKIE [process-5];
echo ftp_pwd($ conn_id)。< br>;
$ server_file = $ _GET ['file'];
$ fp = fopen('php:// stdout','w +');
if(ftp_get($ conn_id,$ fp,$ server_file,FTP_BINARY)){
echo已成功写入$ local_file \ n;
} else {
echoThere's a problem \\\
;
}
ftp_close($ conn_id);
//让浏览器下载任何你输出的
头('Content-type:file / binary');
//设置正确的文件名
header('Content-Disposition:attachment; filename =''。$ file。'');
I am currently implementing a system for users to download files from the ftp without the actual need of a ftp client. I have already developed a login system and have successfully managed to list out the files from the folder. However, I intend to make the download process using ftp_get with a "save as" prompt.
I have referred to http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_23210157.html#mainSection but the solution stated wasn't conclusive.
I did use one of the suggestion in the previous forum topic, but I got a msg "There was a problem" after executing ftp_get.
I will really appreciate with any help given ! Thanks !
//--------------------------- Connects to FTP host ---------------------------------------------
$conn_id = ftp_connect($_COOKIE["process-1"]) or die("Couldn't connect to FTP server");
$login_result = ftp_login($conn_id, $_COOKIE["process-2"], $_COOKIE["process-3"]);
//--------------------------- Validates FTP Logiin (username,password) -------------------------
if(!$login_result) die("FTP Login failed. Contact support @ [email protected]");
ftp_pasv($conn_id,true);
$current_dir = ftp_pwd($conn_id);
$chdir = ftp_chdir($conn_id,$_COOKIE["process-5"]);
if(!$chdir) echo "Change Directory failed. Origin = " .$current_dir. "; Destination: ".$_COOKIE["process-5"];
echo ftp_pwd($conn_id) ."<br>";
$server_file = $_GET['file'];
$fp = fopen('php://stdout', 'w+');
if (ftp_get($conn_id, $fp, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
ftp_close($conn_id);
// make the browser download anything you output
header('Content-type: file/binary');
// set the correct filename
header('Content-Disposition: attachment; filename="'.$file.'"');
这篇关于下载提示输入ftp_get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!