php 判断远程文件是否存在,如何使用PHP检查远程文件是否存在?

派斯说你可以用卷发。你可以让卷曲只给你的标题,而不是身体,这可能会使它更快。一个糟糕的域总是需要一段时间,因为您将等待请求超时;您可能会使用curl更改超时长度。

下面是一个例子:function remoteFileExists($url) {

$curl = curl_init($url);

//don't fetch the actual page, you only want to check the connection is ok

curl_setopt($curl, CURLOPT_NOBODY, true);

//do request

$result = curl_exec($curl);

$ret = false;

//if request did not fail

if ($result !== false) {

//if request was ok, check response code

$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($statusCode == 200) {

$ret = true;

}

}

curl_close($curl);

return $ret;}$exists = remoteFileExists('http://stackoverflow.com/favicon.ico');if ($exists) {

echo 'file exists';} else {

echo 'file does not exist';   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值