龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP检测远端文件是否存在

时间:2014-07-20 15:54来源:网络整理 作者:网络 点击:
分享到:
PHP检测远端文件是否存在 lt;?phpfunction get_http_response_code($theURL) {$headers = get_headers($theURL);return substr($headers[0], 9, 3);}?gt;[代码片段(28行)]

<?php

function get_http_response_code($theURL) {

$headers = get_headers($theURL);

return substr($headers[0], 9, 3);

}

?>

<?php
/**
 * Fetches all the real headers sent by the server in response to a HTTP request without redirects
 * 获取不包含重定向的报头
 */

function get_real_headers($url,$format=0,$follow_redirect=0) {
  if (!$follow_redirect) {
    //set new default options
    $opts = array('http' =>
        array('max_redirects'=>1,'ignore_errors'=>1)
    );
    stream_context_get_default($opts);
  }
  //get headers
    $headers=get_headers($url,$format);
    //restore default options
  if (isset($opts)) {
    $opts = array('http' =>
        array('max_redirects'=>20,'ignore_errors'=>0)
    );
    stream_context_get_default($opts);
  }
  //return
    return $headers;
}
?>
//该片段来自于http://outofmemory.cn
精彩图集

赞助商链接