jasekz/laradrop
Composer 安装命令:
composer require jasekz/laradrop
包简介
File manager using Dropzone.js for Laravel 5 | 6 | 7 | 8
README 文档
README
This uses SoftDelete
Laradrop
This is a file manager using Dropzone.js for Laravel 5, 6, 7, 8. It provides basic functionality for managing, uploading, and deleting files.
Quick Start
-
Follow the Installation instructions below.
Getting errors? Make sure you have a database set up (https://laravel.com/docs/database). -
In a view (welcome.blade.php, for example), add:
<html> <head> <title>Laradrop Demo</title> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css"> <link href="/vendor/jasekz/laradrop/css/styles.css" rel="stylesheet" type="text/css"> <link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet" type="text/css"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" ></script> <script src="/vendor/jasekz/laradrop/js/enyo.dropzone.js"></script> <script src="/vendor/jasekz/laradrop/js/laradrop.js"></script> </head> <body> <div class="laradrop" laradrop-csrf-token="{{ csrf_token() }}"> </div> </body> <script> jQuery(document).ready(function(){ jQuery('.laradrop').laradrop(); }); </script> </html>
- In your .env file, add:
LARADROP_DISK_PUBLIC_URL=/uploads
LARADROP_DISK=laradrop
- In your config/filesystems.php, add to your
disksarray:
'laradrop' => [
'driver' => 'local',
'root' => public_path('uploads'), // will put files in 'public/upload' directory
],
That's it. If you have any issues or question, please feel free to open an issue.
Installation
NOTE: If you haven't set up a database yet for your app, please do that first as per Laravel docs - http://laravel.com/docs/database.
Via composer
composer require jasekz/laradrop
Then in your config/app.php add
'Jasekz\Laradrop\LaradropServiceProvider'
to the providers array.
Then run
php artisan vendor:publish
followed by
php artisan migrate
Configuration (.env)
Laradrop uses Laravel's Filesystem mechanism (https://laravel.com/docs/filesystem) and by default will store your
files in the storage/app directory. If you would like to modify this behavior, along with other default settings, you can set your .env file variables:
# s3, local, or Rackspace. See 'Other Driver Prerequisites' at https://laravel.com/docs/filesystem. Defaults to 'local' LARADROP_DISK=local # If your files need to be web accessible, set this param. S3, for example, would be 'https://s3.amazonaws.com/my-bucket'. Defaults to the web root (public). LARADROP_DISK_PUBLIC_URL=/img # If a thumbnail can not be generated due to incompatible file or any other reason, what image do you want to use? Defaults to 'vendor/jasekz/laradrop/img/genericThumbs/no-thumb.png' LARADROP_DEFAULT_THUMB=/img/no-thumb.png # Max file upload size in MB. Defaults to 10. LARADROP_MAX_UPLOAD_SIZE=20 # Max file size (in MB) for which thumbnail generation will be attempted. If your server has an issue processing thumbs, you can lower this value. Defaults to 10. LARADROP_MAX_THUMBNAIL_SIZE=10 # Defaults to 150px. LARADROP_THUMB_WIDTH=150 # Defaults to 150px. LARADROP_THUMB_HEIGHT=150 # Run laradrop routes through middlware. Defaults to none. LARADROP_MIDDLEWARE=web
Usage
This package requires Dropzone.js, jQuery, and jQuery UI. Include these somewhere in your template:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" ></script> <script src="/vendor/jasekz/laradrop/js/enyo.dropzone.js"></script> <script src="/vendor/jasekz/laradrop/js/laradrop.js"></script>
By default, Laradrop is designed for Bootstrap, but it's not a requirement. Include Bootstrap and the Laradrop styles if you'd like to use it:
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/vendor/jasekz/laradrop/css/styles.css" rel="stylesheet" type="text/css">
Add the html code where you'd like to implement the file manager. Note, that by default, there is no middleware assigned to the Laradrop controller, however, it you assign middleware which contains csrf protection, you must include the laradrop-csrf-token="{{ csrf_token() }}" attribute.
<div class="laradrop" laradrop-csrf-token="{{ csrf_token() }}"> </div>
Finally, bind it using jQuery:
<script> jQuery(document).ready(function(){ // Simplest: jQuery('.laradrop').laradrop(); // With custom params: jQuery('.laradrop-custom').laradrop({ breadCrumbRootText: 'My Root', // optional actionConfirmationText: 'Sure about that?', // optional onInsertCallback: function (obj){ // optional // if you need to bind the select button, implement here alert('Thumb src: '+obj.src+'. File ID: '+obj.id+'. Please implement onInsertCallback().'); }, onErrorCallback: function(msg){ // optional // if you need an error status indicator, implement here alert('An error occured: '+msg); }, onSuccessCallback: function(serverRes){ // optional // if you need a success status indicator, implement here } }); }); </script>
Events
Laradrop currently fires two events:
- Jasekz\Laradrop\Events\FileWasUploaded - this is fired after a file has been uploaded and saved.
- Jasekz\Laradrop\Events\FileWasDeleted - this is fired after a file is deleted.
Handlers (upload, delete, list, etc)
If you'd like to implement your own hanldlers (or extend the existing ones with your own controllers), you can do so. All you need to do, is to defined the routes to the appropriate handlers in the button attributes. This also allows you to easily have multiple handlers for different use cases, if so desired.
<div class="laradrop" laradrop-file-source="{{ route('yourRoute.index') }}" laradrop-upload-handler="{{ route('yourRoute.store') }}" laradrop-file-delete-handler="{{ route('yourRoute.destroy', 0) }}" laradrop-file-move-handler="{{ route('yourRoute.move') }}" laradrop-file-create-handler="{{ route('yourRoute.create') }}" laradrop-containers="{{ route('yourRoute.containers') }}" laradrop-csrf-token="{{ csrf_token() }}" laradrop-allow=".pdf"> </div>
File type validations
The default implementation of accept checks the file's mime type or extension against this list. This is a comma separated list of mime types or file extensions.
Eg.: image/*,application/pdf,.psd
If the Dropzone is clickable this option will also be used as accept parameter on the hidden file input as well.
License
The MIT License (MIT). Please see License File for more information.
jasekz/laradrop 适用场景与选型建议
jasekz/laradrop 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 10.27k 次下载、GitHub Stars 达 71, 最近一次更新时间为 2015 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「file manager」 「file upload」 「laravel 5」 「dropzone.js」 「laravel 6」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jasekz/laradrop 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jasekz/laradrop 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jasekz/laradrop 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
Text file manipulation
KCFinder web file manager
统计信息
- 总下载量: 10.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 73
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-16