thinkphp5 获取上传图片的大小和信息
先看一下打印出对象信息如下。object(think\File)#19 (13) {
["error":"think\File":private] => string(0) ""
["filename":protected] => string(77) "E:\WWW\im_liaosp\public\uploads\20180620\e4c230cf5432223ea1f28a7b31b44ac7.png"
["saveName":protected] => string(45) "20180620/e4c230cf5432223ea1f28a7b31b44ac7.png"
["rule":protected] => string(4) "date"
["validate":protected] => array(0) {
}
["isTest":protected] => NULL
["info":protected] => array(5) {
["name"] => string(31) "0180620202751.png"
["type"] => string(9) "image/png"
["tmp_name"] => string(21) "D:\phptmp\phpB7C3.tmp"
["error"] => int(0)
["size"] => int(48182)
}
["hash":protected] => array(0) {
}
["pathName":"SplFileInfo":private] => string(56) "./uploads/\20180620/e4c230cf5432223ea1f28a7b31b44ac7.png"
["fileName":"SplFileInfo":private] => string(36) "e4c230cf5432223ea1f28a7b31b44ac7.png"
["openMode":"SplFileObject":private] => string(1) "r"
["delimiter":"SplFileObject":private] => string(1) ","
["enclosure":"SplFileObject":private] => string(1) """
}
获取信息使用这个即可 $fileobj->getInfo();
$info = $fileobj->getInfo();
array(5) {
["name"] => string(31) "20180620202751.png"
["type"] => string(9) "image/png"
["tmp_name"] => string(21) "D:\phptmp\gongfuma.tmp"
["error"] => int(0)
["size"] => int(48182)
}