日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 Thinkphp 正文

tp5.1 獲取原始上傳文件名

更新時間: 2020-07-27 Thinkphp

打印一下上傳的文件對象可以的得出,大致對象結構如下

object(think\File)#91 (13) {
["error":"think\File":private] => string(0) ""
["filename":protected] => string(14) "/tmp/phpYohoFK"
["saveName":protected] => NULL
["rule":protected] => string(4) "date"
["validate":protected] => array(0) {
}
["isTest":protected] => NULL
["info":protected] => array(5) {
["name"] => string(24) "11_190523173145_1-lp.jpg"
["type"] => string(10) "image/jpeg"
["tmp_name"] => string(14) "/tmp/phpYohoFK"
["error"] => int(0)
["size"] => int(10841)
}
["hash":protected] => array(0) {
}
["pathName":"SplFileInfo":private] => string(14) "/tmp/phpYohoFK"
["fileName":"SplFileInfo":private] => string(9) "phpYohoFK"
["openMode":"SplFileObject":private] => string(1) "r"
["delimiter":"SplFileObject":private] => string(1) ","
["enclosure":"SplFileObject":private] => string(1) """
}

看這結構,訪問權限是protected,如何獲取呢?

獲取方法:

對象->getInfo() 獲取info屬性

代碼示例

$file_info = request()->file('file');
$file_name = $file_info->getInfo()['name'];


欄目分類
最近更新