diff --git a/models/Share.php b/models/Share.php index 3f98db4..c24bb01 100644 --- a/models/Share.php +++ b/models/Share.php @@ -2,6 +2,7 @@ namespace app\models; +use Yii; use yii\db\ActiveQuery; use yii\db\ActiveRecord; @@ -99,6 +100,20 @@ class Share extends ActiveRecord { $this->dl_count += 1; $this->save(true, ['dl_count']); - } + + /** + * Give me the file name of the shared file/folder. + * @return string + */ + public function getShareFileName(): string + { + return basename($this->getAbsoluteFilePath()); + } + + public function getAbsoluteFilePath(): string + { + return Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $this->sharer_id . '/' . $this->file_relative_path; + } + } diff --git a/utils/FileSizeHelper.php b/utils/FileSizeHelper.php index 65b8aff..02114f3 100644 --- a/utils/FileSizeHelper.php +++ b/utils/FileSizeHelper.php @@ -231,4 +231,18 @@ class FileSizeHelper return max(0, (int)$valueInMB); } + public static function getFormatFSize(string $absolutePath): string + { + //detect path is file or folder or not exist + if (!file_exists($absolutePath)) { + return 'ERROR 文件/文件夹不存在'; + } + + if (is_dir($absolutePath)) { + return self::formatBytes(self::getDirectorySize($absolutePath)); + } else { + return self::formatBytes(filesize($absolutePath)); + } + } + } \ No newline at end of file diff --git a/views/share/_file_info.php b/views/share/_file_info.php index 724fa56..635a2ae 100644 --- a/views/share/_file_info.php +++ b/views/share/_file_info.php @@ -2,17 +2,25 @@ /** @var yii\web\View $this */ /** @var app\models\Share $model */ /** @var bool $isDirectory */ + /** @var string $sharerUsername */ + +use app\assets\FontAwesomeAsset; +use app\utils\FileSizeHelper; use yii\bootstrap5\Html; use yii\helpers\Url; - -$this->title = '文件信息'; +FontAwesomeAsset::register($this); +$this->title = '分享信息'; $this->params['breadcrumbs'][] = $this->title; ?>
-

title) ?>

- +

+ + title) ?> +

+

getShareFileName() ?>

+

大小: getAbsoluteFilePath())?>

分享者:

分享创建日期: creation_date) ?>