1

I got a ftp server with a file called "file.txt".
On my website, i would like to show what this file contains using 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);
?>

1 Answer 1

1

Do it like that:

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

echo $string; 
?>
Sign up to request clarification or add additional context in comments.

2 Comments

What i have done is: function test() { $file = $_SERVER['DOCUMENT_ROOT'] . "/file.txt"; //Path to your *.txt file $contents = file($file); $string = implode($contents); echo $string; } But what happends is that it tries to open a file called "file.txt" from my webhost, cause when creating file.txt in my webhost, it does show eveything inside this file
Ahh never mind i change $_SERVER to $ftp_server. Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.