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


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

object(think\File)#77 (13) {
  ["error":"think\File":private] => string(0) ""
  ["filename":protected] => string(14) "/tmp/phpkIAvIy"
  ["saveName":protected] => NULL
  ["rule":protected] => string(4) "date"
  ["validate":protected] => array(0) {
  }
  ["isTest":protected] => NULL
  ["info":protected] => array(5) {
    ["name"] => string(10) "ebrima.ttf"
    ["type"] => string(24) "application/octet-stream"
    ["tmp_name"] => string(14) "/tmp/phpkIAvIy"
    ["error"] => int(0)
    ["size"] => int(907232)
  }
  ["hash":protected] => array(0) {
  }
  ["pathName":"SplFileInfo":private] => string(14) "/tmp/phpkIAvIy"
  ["fileName":"SplFileInfo":private] => string(9) "phpkIAvIy"
  ["openMode":"SplFileObject":private] => string(1) "r"
  ["delimiter":"SplFileObject":private] => string(1) ","
  ["enclosure":"SplFileObject":private] => string(1) """
}

看这结构,访问权限是protected,如何获取呢?

获取方法:

对象->getInfo() 获取info属性

//对象->getInfo() 获取info属性,['name']  获取name的值
$file->getInfo()['name']


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM