1

我有一个带有一个名为“file.txt”的文件的 ftp 服务器。
在我的网站上,我想使用 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);
?>
4

1 回答 1

1

这样做:

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

echo $string; 
?>
于 2013-11-04T11:59:55.577 回答