Code Monkey home page Code Monkey logo

laupload's Introduction

Version License PHP version GitHub tag

一个 laravel 的上传组件

安装

composer global require fxp/composer-asset-plugin
composer require guanguans/laupload

使用

注册服务

config/app.php 中:

'providers' => [
    ...
    guanguans\laupload\LauploadServiceProvider::class,
],

或者 app/Providers/AppServiceProvider.php 中:

...
public function register()
{
    $this->app->register('guanguans\laupload\LauploadServiceProvider');
}
php artisan vendor:publish --provider="guanguans\laupload\LauploadServiceProvider"

配置

return [
    ...
    'uploadStore'  => 'uploadStore', // 上传文件路由
    'uploadFileList' => 'uploadFileList', // 获取文件列表路由
];

视图

<div class="col-md-4">
    <!----------文件视图----------->
    {!! laupload_widget('file') !!}
    <!----------单图视图----------->
    {!! laupload_widget('oneImage') !!}
    <!----------多图视图----------->
    {!! laupload_widget('muiImage') !!}
    <!----------移动端视图--------->
    {!! laupload_widget('app') !!}
</div>

后台

use guanguans\laupload\Laupload;
...
public function store()
{
    $upload = new Laupload();
    $upload->savePath = storage_path('app/public/laupload') . '/'; // 上传根目录
    if ($upload->upload()) {
        // 成功时返回数据 message 为文件地址
        $data = ['valid' => 1, 'message' => asset('storage/app/public/laupload/'.$upload->getUploadFileInfo()[0]['savename'])];
    } else {
        // 失败时返回数据 message 为失败原因
        $data = ['valid' => 0, 'message' => "后台提示:" . $upload->getErrorMsg()];
    }

    return $data;
}

License

MIT

laupload's People

Contributors

guanguans avatar imgbotapp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.