This question already has answers here:
Fastest way to check remote file existance
(5个答案)
4年前关闭。
我正在尝试检查arXiv中是否存在pdf文件。有两个例子
arxiv.org/pdf/1207.4102.pdf
arxiv.org/pdf/1207.41021.pdf
第一个是pdf文件,第二个不是pdf文件,并返回error page。
有没有一种方法可以检查网址是否为pdf。我尝试了How do I check if file exists in jQuery or JavaScript?中的答案,但是它们都不起作用,并且两个网址都返回true(即文件存在)。有没有办法找到JavaScript / jQuery甚至PHP中的pdf文件是哪个网址?
可以使用pdf.js解决吗?
javascript参考方案
它返回正确的结果。
function getHTTPCode($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpcode;
}
$url = 'http://arxiv.org/pdf/1207.41021.pdf';
if(getHTTPCode($url)==200) {
echo 'found';
} else {
echo 'not found';
}
用PHP返回Confirm()[重复] - javascriptThis question already has answers here: PHP parse/syntax errors; and how to solve them (18个回答) …
jQuery val函数在隐藏字段上不起作用? - javascript这是我的HTML代码:<div style='display:none;' id='allformid'> <div> <form action='#'> <input type='text' name='name' …
mysqli_query在功能内部自动激活? [重复] - javascriptThis question already has answers here: What is the difference between client-side and server-side programming? (4个答案) …
写一行到javascript文件 - javascript我正在使用数组来显示网站中的一些图像:var paintingImages; paintingImages = [ { url: 'images/objects/ron.jpg', alt: 'ron' } ]; 该js代码写在paintings.js中,我的主要js代码写在main.js文件中我已经为艺术家制作了这个…
提交初始化后删除某些帖子数据 - javascript在初始化提交之后但在将数据发送到处理页面之前,是否可以过滤$ _POST表单数据?我想象过程的方式:提交->收集$ _POST数据->发送数据我想做的事:提交->收集$ _POST数据->删除某些元素->发送数据这样就不必更改处理页面以过滤掉不希望接收的元素了吗? javascript大神给出的解决方案 当然可以,您可以在JS …