[英]Using php to show a file on ftp server
I got a ftp server with a file called "file.txt". 我有一个名为“ file.txt”的文件的ftp服务器。
On my website, i would like to show what this file contains using php. 在我的网站上,我想显示使用php包含的文件。
what i got: 我得到了什么:
<?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);
?>
Do it like that: 那样做:
<?php
$file = $_SERVER['DOCUMENT_ROOT'] . "/text.txt"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);
echo $string;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.