以前在找了 MIME 的一些资料,只显示 doc、xls 等 office 2002 之类的格式有 MIME
如 .doc MIME 就设置成 application/msword 就可以了。在网页里面docx 文件是没问题,但是下载下来了之后就变成doc格式了,虽然打开是没问题,但总感觉有点不爽。今天我又搜索了一些。搜到了:
原文网址
.dotx,application/vnd.openxmlformats-officedocument.wordprocessingml.template.docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document.xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation
.doc,application/msword
.dot,application/msword
.xls,application/vnd.ms-excel
文件的大小函数为:filesize()
文件是否存在的函数为:file_exits();
但是这两个函数只针对本地
那么:远程文件是否存在,远程文件大小 如何得知呢?
搜索了一下,有人居然说,把远程文件下载过来再判断这个远程文件的大小,这是什么歪理。
庆幸大部分人还是清醒的,一般应该使用判断header反馈的信息进行判断。
php中如何获得header信息呢? php的函数真多,这个也不例外
1.最简单的获取远程文件大小办法
$a_array = get_headers(url,true);
url就是网址了,至于第二个参数
就可以得到类似下面的这个数组
Array
(
[0] => HTTP/1.1 200 OK
[Date] => Sat, 29 May 2004 12:28:14 GMT
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
[ETag] => “3f80f-1b6-3e1cb03b”
[Accept-Ranges] => bytes
[Content-Length] => 438
[Connection] => close
[Content-Type] => text/html
)
所以,你可以很舒服的拿到远程文件的大小
$file_sizeofurl = a_array['Content-Length'];
2.用curl获取远程文件大小
如果服务器禁止get_headers 怎么办?
换一种办法,用curl
我总觉得curl就像一个虚拟的用户,什么都能模仿
下面直接给出一个老外的函数
请注意
echo ‘
head–>’.$head.’<—-end
‘;
这句是我加的,为了知道header里面到底包含了什么东西
function remote_filesize($uri,$user=”,$pw=”)
{
// start output buffering
ob_start();
// initialize curl with given uri
$ch = curl_init($uri);
// make sure [...]