2013-11-04 72 views
1

我得到一個名爲「file.txt」的文件的FTP服務器。
在我的網站上,我想用php顯示這個文件包含的內容。
我得到了什麼:使用PHP在FTP服務器上顯示一個文件

<?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

那樣做:

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

echo $string; 
?> 
+0

我做了什麼是: 功能測試(){ $ 文件= $ _ SERVER [ 'DOCUMENT_ROOT']。 「/file.txt」; //路徑到你的* .txt文件 $ contents = file($ file); $ string = implode($ contents); echo $ string; } } 但是發生了什麼是它試圖從我的虛擬主機打開一個名爲「file.txt」的文件,因爲在我的虛擬主機中創建file.txt時,它確實在此文件中顯示了eveything –

+0

啊沒關係我更改$ _SERVER到$ ftp_server。非常感謝 –

相關問題