teertz/filepath

生成静态文件的路径

v1.0.3 2016-10-12 16:34 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:19:59 UTC


README

简介

Teertz Filepath 提供了一种简单的方法,在服务器上生成用于大量静态文件(如用户图片)的随机路径

生成的路径如下:BASE_DIR.'/vrt/ssd/tgh/';

基本用法

要开始使用 Teertz Filepath,将其添加到您的 composer.json 文件中作为依赖项

composer require teertz/filepath

获取完整路径

<?php

use Teertz\Filepath\Generator as FilepathGenerator;

class SomeClass
{
    public function uploadSomePhoto($filename)
    {
        /* some work before */
        $filepath = new FilepathGenerator('/var/www/static/images/');
        /* some work after */
        
        return $filepath->getFullPath().$filename;

    }
}

您将获得 BASE_DIR + 随机路径,例如:/var/www/static/images/ddr/ggs/rrt/{filename}

仅获取生成路径

<?php

use Teertz\Filepath\Generator as FilepathGenerator;

class SomeClass
{
    public function uploadSomePhoto($filename)
    {
        /* some work before */
        $filepath = new FilepathGenerator('/var/www/static/images/');
        /* some work after */
        
        return $filepath->getGeneratedPath().$filename;

    }
}

您将获得随机路径,例如:/fth/asf/bkf/{filename}

与 Laravel 配置

Filepath 门面添加到您的 app 配置文件中的 aliases 数组

'Filepath' => Teertz\Filepath\Generator::class,

许可

Teertz Filepath 是开源软件,采用MIT 许可证发布