在 PHP 中获取远程文件文件大小的最简单方法?

问题描述:

我想用 cURL 做一个 head 请求,想知道这是否可行?

I was thinking of doing a head request with cURL, was wondering if this is the way to go?

是的.由于文件是远程文件,您完全依赖于 Content-Length 标头的值(除非您想下载整个文件).您需要 curl_setopt($ch, CURLOPT_NOBODY, true)curl_setopt($ch, CURLOPT_HEADER, true).

Yes. Since the file is remote, you're completely dependent on the value of the Content-Length header (unless you want to download the whole file). You'll want to curl_setopt($ch, CURLOPT_NOBODY, true) and curl_setopt($ch, CURLOPT_HEADER, true).