[李景山php]每天TP5-20170104|thinkphp5-File.php-1

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------

namespace think;

use SplFileInfo;// Spl 文件信息 类库
use SplFileObject;// Spl 文件对象 类库
// Spl 一个需要面对的问题

class File extends SplFileObject
{// 文件 继承 SplFileObject 对象
    /**
     * 错误信息
     * @var string
     */
    private $error = ‘‘;// 错误信息存储
    // 当前完整文件名
    protected $filename;// 当前完整的文件名 信息
    // 上传文件名
    protected $saveName;// 上传 文件名
    // 文件上传命名规则
    protected $rule = ‘date‘;// 文件上传的 命名规则
    // 文件上传验证规则
    protected $validate = [];// 文件上传 验证规则
    // 单元测试
    protected $isTest;// 单元测试
    // 上传文件信息
    protected $info;// 上传文件信息
    // 文件hash信息
    protected $hash = [];// 文件 hash 信息

    public function __construct($filename, $mode = ‘r‘)// 结构体
    {
        parent::__construct($filename, $mode);// 函数 构造体 父亲的
        $this->filename = $this->getRealPath();// 获取 文件名称
    }

    /**
     * 是否测试
     * @param  bool   $test 是否测试
     * @return $this
     */
    public function isTest($test = false)
    {
        $this->isTest = $test;// 是否测试信息
        return $this;
    }

    /**
     * 设置上传信息
     * @param  array   $info 上传文件信息
     * @return $this
     */
    public function setUploadInfo($info)
    {
        $this->info = $info;// 设置 上传文件信息
        return $this;
    }

    /**
     * 获取上传文件的信息
     * @param  string   $name
     * @return array|string
     */
    public function getInfo($name = ‘‘)
    {
        return isset($this->info[$name]) ? $this->info[$name] : $this->info;// 获取上传文件信息
    }

    /**
     * 获取上传文件的文件名
     * @return string
     */
    public function getSaveName()
    {
        return $this->saveName;// 获取存储的文件名
    }

    /**
     * 设置上传文件的保存文件名
     * @param  string   $saveName
     * @return $this
     */
    public function setSaveName($saveName)// 设置存储的文件名
    {
        $this->saveName = $saveName;
        return $this;
    }

    /**
     * 获取文件的md5散列值
     * @return $this
     */
    public function md5()// md5 加密文件
    {
        if (!isset($this->hash[‘md5‘])) {
            $this->hash[‘md5‘] = md5_file($this->filename);
        }
        return $this->hash[‘md5‘];
    }

    /**
     * 获取文件的sha1散列值
     * @return $this
     */
    public function sha1()// sha1 文件 散列值
    {
        if (!isset($this->hash[‘sha1‘])) {
            $this->hash[‘sha1‘] = sha1_file($this->filename);
        }
        return $this->hash[‘sha1‘];
    }

    /**
     * 检查目录是否可写
     * @param  string   $path    目录
     * @return boolean
     */
    protected function checkPath($path)//目录 检测
    {
        if (is_dir($path)) {
            return true;
        }

        if (mkdir($path, 0755, true)) {
            return true;
        } else {
            $this->error = "目录 {$path} 创建失败!";
            return false;
        }
    }

    /**
     * 获取文件类型信息
     * @return string
     */
    public function getMime()
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);// 获取文件 类型
        return finfo_file($finfo, $this->filename);
    }

    /**
     * 设置文件的命名规则
     * @param  string   $rule    文件命名规则
     * @return $this
     */
    public function rule($rule)
    {// 规则设置
        $this->rule = $rule;
        return $this;
    }

    /**
     * 设置上传文件的验证规则
     * @param  array   $rule    验证规则
     * @return $this
     */
    public function validate($rule = [])
    {// 验证规则
        $this->validate = $rule;
        return $this;
    }

    /**
     * 检测是否合法的上传文件
     * @return bool
     */
    public function isValid()
    {// 检测 文件 是否 合法
        if ($this->isTest) {
            return is_file($this->filename);// 验证是否 为文件
        }
        return is_uploaded_file($this->filename);// 验证 是否 为 上传文件
    }
时间: 2024-08-01 10:45:08

[李景山php]每天TP5-20170104|thinkphp5-File.php-1的相关文章

tp5 No input file specified.

我的是windows10 系统,phpstudy 环境 ,配置的本地虚拟机,tp5.1 访问跟目录正常 访问次级页面报错 对于 tp5  No input file specified.  的问题,其实是 .htaccess 文件的配置问题 源文件是这样的 <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On  RewriteCond %{REQUEST_FILENAME} !-d Rewri

[李景山php]每天laravel-20161106|EngineResolver.php

<?php namespace Illuminate\View\Engines; use Closure; use InvalidArgumentException; class EngineResolver {// engineResolver     /**      * The array of engine resolvers.      *      * @var array      */     protected $resolvers = [];// The array of e

[李景山php]每天laravel-20161107|PhpEngine.php

<?php namespace Illuminate\View\Engines; use Exception; use Throwable; use Symfony\Component\Debug\Exception\FatalThrowableError; class PhpEngine implements EngineInterface {// PhpEngine implements EngineInterface     /**      * Get the evaluated con

[李景山php]每天laravel-20161010|Validator.php-10

   /**     * Validate the guessed extension of a file upload is in a set of file extensions.     *     * @param  string  $attribute     * @param  mixed  $value     * @param  array   $parameters     * @return bool     */    protected function validate

[李景山php]每天laravel-20161011|Validator.php-11

/**  * Given two date/time strings, check that one is after the other.  *  * @param  string  $format  * @param  string  $before  * @param  string  $after  * @return bool  */ protected function checkDateTimeOrder($format, $before, $after) {     $befor

[李景山php]每天laravel-20160915|FileSystemManager-2

    /**      * Create an instance of the local driver.      *      * @param  array  $config      * @return \Illuminate\Contracts\Filesystem\Filesystem      */     public function createLocalDriver(array $config)     {         $permissions = isset($co

[李景山php]每天TP5-20161210|Config.php

<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006~2016 http://thinkphp.cn All righ

[李景山php]每天TP5-20161204|Loader.php-2

    public static function autoload($class)// 这个就加载文件     {// 自动加载 类 // 加载一个class         // 检测命名空间别名         if (!empty(self::$namespaceAlias)) {// 如果有命名空间             $namespace = dirname($class);// 通过类名 的路径 来的 命名空间             if (isset(self::$nam

[李景山php]每天TP5-20170105|thinkphp5-File.php-2

    /**      * 检测上传文件      * @param  array   $rule    验证规则      * @return bool      */     public function check($rule = [])     {// 检测 上传 文件         $rule = $rule ?: $this->validate;// rule 规则 获取         /* 检查文件大小 */         if (isset($rule['size'])

[李景山php]每天TP5-20170201|thinkphp5-Request.php-4

/**  * 设置获取获取当前请求的参数  * @access public  * @param string|array  $name 变量名  * @param mixed         $default 默认值  * @param string|array  $filter 过滤方法  * @return mixed  */ public function param($name = '', $default = null, $filter = null) {// 设置 或者 获取 当前