Airship\Cabin\Bridge\Blueprint\Files::getFileInfo PHP Method

getFileInfo() public method

Get detailed file information
public getFileInfo ( string $cabin = '', array $path = null, string $filename = '' ) : array
$cabin string
$path array
$filename string
return array
    public function getFileInfo(string $cabin = '', $path = null, string $filename = '') : array
    {
        if (empty($path)) {
            $fileInfo = $this->db->row('SELECT
                     *
                 FROM
                     airship_files
                 WHERE
                         directory IS NULL
                     AND cabin = ?
                     AND filename = ?', $cabin, $filename);
        } else {
            $fileInfo = $this->db->row('SELECT
                     *
                 FROM
                     airship_files
                 WHERE
                         directory = ?
                     AND filename = ?', $path, $filename);
        }
        if (empty($fileInfo)) {
            throw new FileNotFound();
        }
        if (\file_exists(AIRSHIP_UPLOADS . $fileInfo['realname'])) {
            $fileInfo['size'] = \filesize(AIRSHIP_UPLOADS . $fileInfo['realname']);
        } else {
            $fileInfo['size'] = 0;
        }
        return $fileInfo;
    }

Usage Example

Esempio n. 1
0
 /**
  * Move/rename a file
  *
  * @param string $file
  * @param string $path
  * @param string $cabin
  */
 protected function commonMoveFile(string $file, string $path, string $cabin)
 {
     if (!$this->permCheck()) {
         \Airship\redirect($this->airship_cabin_prefix);
     }
     list($publicPath, $root) = $this->loadCommonData($path, $cabin);
     if (empty($root)) {
         $fileInfo = $this->files->getFileInfo($cabin, null, $file);
     } else {
         $fileInfo = $this->files->getFileInfo($cabin, $root, $file);
     }
     $post = $this->post(new MoveFileFilter());
     if (!empty($post)) {
         $this->files->moveFile($fileInfo, $post, $cabin);
         \Airship\redirect($this->airship_cabin_prefix . '/' . $this->path_middle . '/' . $cabin, ['dir' => $path]);
     }
     $this->lens('files/move', ['cabins' => $this->getCabinNamespaces(), 'file' => $fileInfo, 'root_dir' => $this->root_dir, 'all_dirs' => $this->files->getDirectoryTree($cabin, $this->root_dir), 'dir' => $path, 'cabin' => $cabin, 'pathinfo' => $publicPath]);
 }