adzpire/yii2-basicfilemanager

基本文件管理器

0.0.1 2016-05-18 03:51 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:29:58 UTC


README

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

composer require adzpire/yii2-basicfilemanager "dev-master"

或者

"adzpire/yii2-basicfilemanager": "dev-master"

将以下内容添加到你的 composer.json 文件的 require 部分中。

用法

扩展安装完成后,只需在你的代码中通过

配置

    'modules' => [
        ...
        'basicfilemanager' => [
            'class' => 'adzpire\basicfilemanager\Module',
            // Upload routes
            'routes' => [
                // Base absolute path to web directory
                'baseUrl' => '',
                // Base web directory url
                'basePath' => '@webroot',
                // Path for uploaded files in web directory
                'uploadPath' => 'uploads',
            ],
        ],
        ...
    ],

独立

<input type="text" name="avatar" id="profile-avatar">
<?php
echo \adzpire\basicfilemanager\widgets\ModalBrowser::widget([
    'browserUrl' => '/basicfilemanager',
    'fieldID' => 'profile-avatar',
    'returnType' => 'basename', //url(default), absolute, behind, basename
        //url คือ ที่อยู่ของไฟล์ (/uploads/images/abc.jpg),
        //absolute คือ ที่อยู่ของไฟล์แบบเต็ม (http://www.example.com/uploads/images/abc.jpg),
        //behind คือ ที่ตั้งไฟล์โดยเริ่มนับจากหลังคอนฟิคไดเรคทอรี่อัพโหลด (images/abc.jpg),
        //basename คือ ใช้ชื่อไฟล์อ่างเดียว (abc.jpg)
    'options' => [
        'subDir' => 'user/10/avatar', //บังคับเข้า dir ตามค่า (default='')
        'changeDir' => false, //การอนุญาตให้เปลี่ยน dir ได้ (default=true)
        'createDir' => false, //การอนุญาติให้สร้าง dir ได้ (default=true)
        'upload' => false, //การอนุญาติให้ upload ได้ (default=true)
    ],
    'modalOptions'=>[ //ค่า config ของ bootstrap modal
        'header' => '<strong>Covers</strong>',
        'id' => 'modalAvatar',
        'toggleButton' => [
            'label' => '<i class="glyphicon glyphicon-picture"></i>', 
            'id' => 'avatar-btn-browse',
            'class'=>'btn btn-default btn-change-avatar'
        ],
    ],
]);
?>

如果你想在选择文件后看到效果,请注册javascript来查看

<?php
$this->registerJS("
function after_selected_function(){
    alert('After selected first.');
}
", $this::POS_HEAD);

$this->registerJS("
function modalAvatar_after_selected_function(){
    alert('After selected second.');
}
", $this::POS_HEAD);
?>