Home  >  Article  >  Backend Development  >  php怎样判断远程文件是否存在

php怎样判断远程文件是否存在

WBOY
WBOYOriginal
2016-06-23 14:01:10799browse

php 有什么方法  来判断远程文件是否存在


回复讨论(解决方案)

$url = 'http://www.example.com';print_r(get_headers($url));print_r(get_headers($url, 1));


获取远程文件HEAD信息。如果等于HTTP/1.1 200 OK 则证明文件存在

能不 能把源码给啊     我不懂  太白了

[code=php]$url = 'http://imgstatic.baidu.com/img/image/d833c895d143ad4bf450b6dd80025aafa40f06b4_%E5%89%AF%E6%9C%AC.jpg';$header = get_headers($url);var_dump($header);if(strpos($header[0],'200') !== false){//存在	echo '存在';}else{//不存在	echo '不存在';}
[/code]

谢谢!!!!!!!!!!!!!!!!!!!!!!!!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn