使用PHP中的URL获取远程文件大小 [英] Get remote file size using URL in PHP
本文介绍了使用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;
这篇关于使用PHP中的URL获取远程文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文