使用PHP中的URL获取远程文件大小

使用PHP中的URL获取远程文件大小

问题描述:

我正在尝试使用来获取图像大小

I am trying to get image size using

get_headers($url)

但是我收到类似

get_headers() [function.get-headers]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in

还有其他方法吗?

谢谢.

您可以使用curl_getinfo()函数获取远程文件的大小.

You can use curl_getinfo() function to get the remote file size.

 $ch = curl_init('http://www.google.co.in/images/srpr/logo4w.png');

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 curl_setopt($ch, CURLOPT_HEADER, TRUE);
 curl_setopt($ch, CURLOPT_NOBODY, TRUE);

 $data = curl_exec($ch);
 $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);

 curl_close($ch);
 echo $size;