如何从url查询pdf文件是否存在


How to check whether a pdf file exists from url?

我正在尝试检查是否有一个arXiv url的形式

http://arxiv.org/pdf/[某个4位数]。[一些4位数].pdf

是PDF文件或HTML页面。我的函数现在看起来像

function is_url_exist($url){
    $ch = curl_init($url);    
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if($code == 200){
       $status = "true";
    }else{
      $status = "false";
    }
    curl_close($ch);
   return $status;
}

问题是该函数对pdf文件http://arxiv.org/pdf/1207.0102.pdf和html页面http://arxiv.org/pdf/1217.2314.pdf都返回false。有办法解决这个问题吗?

为什么不直接检查扩展呢?

<?PHP 
if(strtolower(substr($url, -3, 3)) == "pdf"){
    // Do something with pdf
} else {
    // Not pdf
} 
?>