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. 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 @ 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"];
e开发者_开发问答cho 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. Why are you reinventing the wheel?
Go to any navigable ftp site in your browser by typing ftp://browsableftpsite.com in the URL area.
// make the browser download anything you output
header('Content-type: file/binary');
// set the correct filename
header('Content-Disposition: attachment; filename="'.$file.'"');
精彩评论