获取远程图片字节大小
function Get_Filesize($url){
if(!isset($url) || trim($url) ==''){
return '';
}
ob_start();
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
$okay = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex,$head,$matches);
return isset($matches[1]) && is_numeric($matches[1]) ? $matches[1] : '';
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
$arr = getimagesize("1.jpg");
/**
* 这里$arr为一个数组类型
* $arr[0] 为图像的宽度
* $arr[1] 为图像的高度
* $arr[2] 为图像的格式,包括jpg、gif和png等
* $arr[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy"
*/
img_info = getimagesize(images);
switch (img_info[2]){
case 1:
imgtype = "gif";
break;
case 2:
imgtype = "jpg";
break;
case 3:
imgtype = "png";
break;
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
print_r(exif_imagetype("c:/a")); #可以准确判断图片的类型 返回整形 对应图片常量
--------------------------------------------------------------------------------------------------------------------------------------------------------
$a = 'aaaaa.jpg';
print_r(pathinfo($a));
Array
(
[dirname] => . //文件目录
[basename] => aaaaa.jpg //文件全名
[extension] => jpg //文件后缀
[filename] => aaaaa //文件名
)
--------------------------------------------------------------------------------------------------------------------------------------------------------
//获取文件大小
img_size = ceil(filesize(img)/1000)."k";
-----------------------------------------------------------------------------------------------------------------------------------------
网友评论