PHP code example of guanguans / laupload

1. Go to this page and download the library: Download guanguans/laupload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

guanguans / laupload example snippets

 php
'providers' => [
    ...
    guanguans\laupload\LauploadServiceProvider::class,
],
 php
...
public function register()
{
    $this->app->register('guanguans\laupload\LauploadServiceProvider');
}
 sh
php artisan vendor:publish --provider="guanguans\laupload\LauploadServiceProvider"
 php
return [
    ...
    'uploadStore'  => 'uploadStore', // 上传文件路由
    'uploadFileList' => 'uploadFileList', // 获取文件列表路由
];
 html
<div class="col-md-4">
    <!----------文件视图----------->
    {!! laupload_widget('file') !!}
    <!----------单图视图----------->
    {!! laupload_widget('oneImage') !!}
    <!----------多图视图----------->
    {!! laupload_widget('muiImage') !!}
    <!----------移动端视图--------->
    {!! laupload_widget('app') !!}
</div>
 php
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;
}