php如何查看服务器文件是否存在,如何使用PHP检查远程服务器上是否存在文件?...

我用这个,有点简单:

// 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 "
";

echo "I found ".$check_file_exist." in directory : ".$path;

}

else

{

echo "
";

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);

使用的功能:(感谢middaparka)

>使用ftp_connect登录

>通过ftp_nlist获取远程文件列表

>使用in_array查看文件是否存在于数组中

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值