[英]Download prompt for ftp_get
I am currently implementing a system for users to download files from the ftp without the actual need of a ftp client. 我目前正在实现一个系统,供用户从ftp下载文件,而实际上不需要ftp客户端。 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.
但是,我打算使用带有“另存为”提示的ftp_get进行下载过程。
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. 我已经提到了http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_23210157.html#mainSection,但所提出的解决方案不是结论性的。
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. 我确实使用了上一个论坛主题中的建议之一,但是在执行ftp_get之后收到了消息msg“出现问题”。
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 @ customercare@strategyinstitute.com");
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);
every browser pretty much is already an ftp client. 每个浏览器几乎都已经是ftp客户端。 Why are you reinventing the wheel?
你为什么要重新发明轮子?
Go to any navigable ftp site in your browser by typing ftp://browsableftpsite.com in the URL area. 通过在URL区域中键入ftp://browsableftpsite.com ,转到浏览器中的所有可导航ftp站点。
// make the browser download anything you output
header('Content-type: file/binary');
// set the correct filename
header('Content-Disposition: attachment; filename="'.$file.'"');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.