3 回答

TA貢獻1815條經(jīng)驗 獲得超10個贊
試試這個解決方案:
// the server you wish to connect to - you can also use the server ip ex. 107.23.17.20
$ftp_server = "ftp.example.com";
// set up a connection to the server we chose or die and show an error
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
ftp_login($conn_id,"ftpserver_username","ftpserver_password");
// check if a file exist
$path = "/SERVER_FOLDER/"; //the path where the file is located
$file = "file.html"; //the file you are looking for
$check_file_exist = $path.$file; //combine string for easy use
$contents_on_server = ftp_nlist($conn_id, $path); //Returns an array of filenames from the specified directory on success or FALSE on error.
// Test if file is in the ftp_nlist array
if (in_array($check_file_exist, $contents_on_server))
{
echo "<br>";
echo "I found ".$check_file_exist." in directory : ".$path;
}
else
{
echo "<br>";
echo $check_file_exist." not found in directory : ".$path;
};
// output $contents_on_server, shows all the files it found, helps for debugging, you can use print_r() as well
var_dump($contents_on_server);
// remember to always close your ftp connection
ftp_close($conn_id);

TA貢獻1784條經(jīng)驗 獲得超2個贊
可能的問題/解決方案
首先:您是否驗證了文件的權(quán)限?
第二:使用 ftp_get() ( https://www.php.net/manual/en/function.ftp-get.php ),這將是最方便的。

TA貢獻1836條經(jīng)驗 獲得超4個贊
我已經(jīng)在我的本地檢查了你的代碼。這是工作文件。我已經(jīng)檢查了我的本地文件路徑。
我認為你的路徑有問題。確認路徑是否正確。
并檢查應(yīng)該有 755 或 777 的文件權(quán)限。
這是我的代碼
<?php
$path = 'C:\xampp\htdocs\test\XSCAssets\idea\157406374721215421965dd24e83bf2e7.png';
if (file_exists($path)) {
$tbody = '<td>DATA ON SERVER</td>';
} else {
$tbody = '<td>NO DATA</td>';
}
echo $tbody;
?>
- 3 回答
- 0 關(guān)注
- 200 瀏覽
添加回答
舉報