PHP下載文件時(shí),我們一般會(huì)加上如下的header信息:
header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); header("Accept-Length:".$fileSize); //請(qǐng)用Content-Length header("Content-Disposition: attachment; filename=".$fileName);
其中header("Accept-Length:".$fileSize);
是獲取文件的大小,并可以返回?cái)?shù)據(jù)給瀏覽器展示。
站長(zhǎng)圖庫(kù)卻遇到怎么也獲取不到下載數(shù)據(jù)大小的問(wèn)題,雖然不影響正常的功能,但是為了追求完美,我要探個(gè)究竟。
最后才發(fā)現(xiàn)header("Accept-Length:***");
這其實(shí)是一個(gè)誤導(dǎo),其實(shí)正確的應(yīng)該是header("Content-Length:***");
修改之后,果然就正確了。