jenky/laravel-plupload
Fork: 10 Star: 29 (更新于 2024-11-04 09:44:51)
license: 暂无
Language: PHP .
Plupload package for Laravel 5
最后发布版本: 3.0.1 ( 2019-08-05 12:20:06)
Laravel 5 Plupload
Laravel package for Plupload http://plupload.com.
This package uses some parts of https://github.com/jildertmiedema/laravel-plupload
Installation
Require this package with composer:
composer require jenky/laravel-plupload
Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
For Laravel 5.4 or older
Add the ServiceProvider to the providers array in config/app.php
Jenky\LaravelPlupload\PluploadServiceProvider::class,
and add this to your facades in config/app.php
:
'Plupload' => Jenky\LaravelPlupload\Facades\Plupload::class,
Copy the package config to your local config with the publish command:
php artisan vendor:publish
or
php artisan vendor:publish --provider="Jenky\LaravelPlupload\PluploadServiceProvider"
Usage
Uploading files
1. Use default plupload html
Use the examples found on the plupload site. The Getting Started page is good place to start.
2. Plupload builder
make($id, $url)
Create new uploader.
- $id: the unique identification for the uploader.
- $url: the upload url end point.
{!! Plupload::make('my_uploader_id', route('photos.store'))->render() !!}
or use the helper
{!! plupload()->make('my_uploader_id', route('photos.store')) !!}
// or even shorter
{!! plupload('my_uploader_id', route('photos.store')) !!}
render($view = 'plupload::uploader', array $data = [])
Renders the uploader. You can customize this by passing a view name and it's data. From version 2.0
, you can omit the render
method in the builder if you don't want to set the view or extra data.
3. Use package js file to initialize Plupload (Optional)
If you do not want to write your own js to initialize Plupload, you can use the upload.js
file that included with the package in resources/views/vendor/plupload/assets/js
. Make sure that you already have jQuery
loaded on your page.
Initialize Plupload
<script>
$(function () {
createUploader('my_uploader_id'); // The Id that you used to create with the builder
});
</script>
These following methods are useable with the upload.js
file.
Set Uploader options
setOptions(array $options)
Set uploader options. Please visit https://github.com/moxiecode/plupload/wiki/Options to see all the options. You can set the default global options in config/plupload.php
{!! plupload('my_uploader_id', route('photos.store'))
->setOptions([
'filters' => [
'max_file_size' => '2mb',
'mime_types' => [
['title' => 'Image files', 'extensions' => 'jpg,gif,png'],
],
],
]) !!}
Automatically start upload when files added
Use setAutoStart()
in your builder before calling render() function.
setAutoStart($bool)
-
$bool:
true
orfalse
{!! plupload('my_uploader_id', route('photos.store'))->setAutoStart(true) !!}
Receiving files
file($name, $handler)
- $name: the input name.
- $handler: callback handler.
Use this in your route or your controller. Feel free to modify to suit your needs.
return Plupload::file('file', function($file) {
// Store the uploaded file using storage disk
$path = Storage::disk('local')->putFile('photos', $file);
// Save the record to the db
$photo = App\Photo::create([
'name' => $file->getClientOriginalName(),
'type' => 'image',
// ...
]);
// This will be included in JSON response result
return [
'success' => true,
'message' => 'Upload successful.',
'id' => $photo->id,
// 'url' => $photo->getImageUrl($filename, 'medium'),
// 'deleteUrl' => route('photos.destroy', $photo)
// ...
];
});
Helper is also available
return plupload()->file('file', function($file) {
});
If you are using the package upload.js
file. The url
and deleteUrl
in the JSON payload will be used to generate preview and delete link while the id
will be appended to the uploader as a hidden field with the following format:
<input type="hidden" name="{uploaderId}_files[]" value="{id}" />
.
Please note that the deleteUrl
uses DELETE
method.
最近版本更新:(数据更新于 2024-09-15 08:26:58)
2019-08-05 12:20:06 3.0.1
2018-07-05 11:42:59 3.0.0
2017-09-18 18:49:26 2.0.0
2017-02-07 10:13:42 1.2.2
2016-04-05 10:49:06 1.2.1
2016-02-23 15:47:58 1.2.0
2015-07-03 12:06:10 1.1.8
2015-06-17 17:24:55 1.1.7
2015-06-11 11:05:04 1.1.6
2015-04-14 18:03:47 1.1.5
主题(topics):
laravel, php, plupload
jenky/laravel-plupload同语言 PHP最近更新仓库
2024-11-20 23:58:25 laravel/framework
2024-11-20 18:39:23 danielmiessler/SecLists
2024-11-16 21:54:23 w7corp/easywechat
2024-11-16 04:49:03 coollabsio/coolify
2024-11-13 23:19:14 symfony/symfony
2024-11-13 22:53:21 symfony/var-dumper