UP2 是一个具有多态关系的文件上传器。

3.0.1 2016-09-02 09:48 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:21:49 UTC


README

对于 Laravel 4,请使用 v1.x 分支

UP2 是一个具有多态关系的文件上传器。

安装

要获取主题的最新版本,只需在您的 composer.json 文件中引入它。

"teepluss/up2": "dev-master"

然后您需要运行 composer install 来下载它并更新自动加载器。

一旦主题安装完毕,您需要将服务提供者注册到应用程序中。打开 app/config/app.php 并找到 providers 键。

'providers' => [

    Teepluss\Up2\Up2ServiceProvider::class

]

UP2 还附带了一个门面,它提供了创建集合的静态语法。您可以在 app/config/app.php 文件的 aliases 键中注册门面。

'aliases' => [

    'UP2' => Teepluss\Up2\Facades\Up2::class

]

使用 artisan CLI 发布。

php artisan vendor:publish --provider="Teepluss\Up2\Up2ServiceProvider"

迁移表。

php artisan migrate

用法

上传器配置位于 app/config/up2.php。在此文件中,您可以指定您希望在应用程序中默认使用的上传器驱动程序。UP2 支持 Local 和 S3。

'drivers' => array(

    'local' => array(
        'baseUrl' => url(''),
        'baseDir' => path_public(),
    ),

    's3' => array(
        'key'    => '',
        'secret' => '',
        'region' => 'ap-southeast-1',
        'bucket' => 'teeplus',
    ),

),

然后您必须为想要使用 "UP2" 的模型创建一个形态方法。

use Teepluss\Up2\Up2Trait;
use Illuminate\Database\Eloquent\Model;

class Blog extends Model {

    use Up2Trait;

    public function .....

}

现在您可以使用 "UP2" 进行文件上传。

上传文件并进行缩放。

// Return an original file meta.
UP2::upload(Blog::find(1), Input::file('userfile'))->getMasterResult();
UP2::upload(User::find(1), Input::file('userfile'))->getMasterResult();

// Return all results files uploaded including resized.
UP2::upload(Product::find(1), Input::file('userfile'))->resize()->getResults();

// If you have other fields in table attachments.
UP2::upload(User::find(1), Input::file('userfile'), array('some_id' => 999))->getMasterResult();

// UP2 can upload remote file.
UP2::inject(array('remote' => true))->upload(User::find(1), 'http://domain.com/image.png', array('some_id' => 999))->getResults();

无模型上传。

UP2::upload(null, Input::file('userfile'))->getMasterResult();

注入配置。

UP2::inject(array('subpath' => 'uploads/products'))->upload(Blog::find(1), Input::file('userfile'))->getMasterResult();

查找文件路径。

$blogs = Blog::with('attachments')->get();

foreach ($blogs as $blog)
{
    foreach ($blog->attachments as $attachment)
    {
        echo UP2::lookup($attachment->id);

        // or lookup with scale from config.
        echo UP2::lookup($attachment->id)->scale('l');
    }
}

从存储中删除文件。

$attachmentId = 'b5540d7e6350589004e02e23feb3dc1f';

// Remove a single file.
UP2::remove($attachmentId);

// Remove all files including resized.
UP2::remove($attachmentId, true);

支持或联系

如果您遇到任何问题,请通过 teepluss@gmail.com 联系我们

Support via PayPal