tp5.1 获取原始上传文件名

打印一下上传的文件对象可以的得出,大致对象结构如下

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'];


打印一下上传的文件对象可以的得出,大致对象结构如下

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'];


相关文章

(1)创建数据表: CREATE TABLE IF NOT EXISTS `think_form` ...
组合查询的主体还是采用数组方式查询,只是加入了一些特殊的...
(1)创建模版:/App/Home/View/Form/edit.html   <FORM m...
自定义配置文件user.php: <?php return array(    \'se...
在一些成熟的CMS系统中,后台一般都包含一个配置中心(如织梦...
废话不多说先上图预览下,即本博客的分页; 这个分页类是在...