使用 php 在 ftp 服务器上显示文件


Using php to show a file on ftp server

我得到了一个ftp服务器,其中包含一个名为"file.txt".
在我的网站上,我想使用 php.
显示此文件包含的内容我得到了什么:

<?php
session_start();

$_SESSION["ftp_pass"] = $_POST["pass"];
$_SESSION["ftp_user"] = $_POST["user"];
$ftp_pass = $_POST["pass"];
$ftp_server = "ftp.guusvanwalstijn.nl";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// Error when wrong password/username/server offline
function error_while_connecting() {
echo "Error while connecting to the server";
echo "<br />Probably the password is wrong or the server is offline";
}
//log in
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "succes";
} else {
    error_while_connecting();
    print("<br />Debug: " . $_POST["pass"] . "<br />");
}
ftp_close($conn_id);
?>

这样做:

 <?php
$file = $_SERVER['DOCUMENT_ROOT'] . "/text.txt"; //Path to your *.txt file 
$contents = file($file); 
$string = implode($contents); 
echo $string; 
?>