File indexing completed on 2025-01-26 05:29:15

0001 <?php
0002 
0003 namespace Intervention\Image;
0004 
0005 class File
0006 {
0007     /**
0008      * Mime type
0009      *
0010      * @var string
0011      */
0012     public $mime;
0013 
0014     /**
0015      * Name of directory path
0016      *
0017      * @var string
0018      */
0019     public $dirname;
0020 
0021     /**
0022      * Basename of current file
0023      *
0024      * @var string
0025      */
0026     public $basename;
0027 
0028     /**
0029      * File extension of current file
0030      *
0031      * @var string
0032      */
0033     public $extension;
0034 
0035     /**
0036      * File name of current file
0037      *
0038      * @var string
0039      */
0040     public $filename;
0041 
0042     /**
0043      * Sets all instance properties from given path
0044      *
0045      * @param string $path
0046      */
0047     public function setFileInfoFromPath($path)
0048     {
0049         $info = pathinfo($path);
0050         $this->dirname = array_key_exists('dirname', $info) ? $info['dirname'] : null;
0051         $this->basename = array_key_exists('basename', $info) ? $info['basename'] : null;
0052         $this->extension = array_key_exists('extension', $info) ? $info['extension'] : null;
0053         $this->filename = array_key_exists('filename', $info) ? $info['filename'] : null;
0054 
0055         if (file_exists($path) && is_file($path)) {
0056             $this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
0057         }
0058 
0059         return $this;
0060     }
0061 
0062      /**
0063       * Get file size
0064       * 
0065       * @return mixed
0066       */
0067     public function filesize()
0068     {
0069         $path = $this->basePath();
0070 
0071         if (file_exists($path) && is_file($path)) {
0072             return filesize($path);
0073         }
0074         
0075         return false;
0076     }
0077 
0078     /**
0079      * Get fully qualified path
0080      *
0081      * @return string
0082      */
0083     public function basePath()
0084     {
0085         if ($this->dirname && $this->basename) {
0086             return ($this->dirname .'/'. $this->basename);
0087         }
0088 
0089         return null;
0090     }
0091 
0092 }