Coder Social home page Coder Social logo

laravel-plupload's Introduction

Laravel 5 Plupload

Latest Stable Version Total Downloads License

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 or false
{!! 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.

laravel-plupload's People

Contributors

jenky avatar nickfan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-plupload's Issues

using chunk_path to a dropbox folder.

Hi, I'm using laravel-plupload & upload files to dropbox, for 'chunk_path' => storage_path('plupload') files is not uploaded to dropbox. I'm using league/flysystem-dropbox package to upload files in dropbox. have any solution?

how to add params on upload?

how to add params on upload?
i add code to Plupload::make()->setOptions():

            'headers' => [
                'X-CSRF-TOKEN' => csrf_token(),
            ],
            'multipart'=>true,
            'multipart_params'=>[
                'mydata_id'=>1,
                'mydata_key'=>2,
            ],

in controller:

    public function uploadRecordAttach(Request $request){
        return \Plupload::file('up_record_attach', function($file) use ($request)
        {
            $mydata_id = $request->get('mydata_id',0);
            $mydata_key = $request->get('mydata_key',0);
          ...

but i got nothing inside Plupload callback?

Laravel 6

Hi,
When do you support Laravel 6?

best,
Sebastian

Bug report

File /src/File.php line 117:

            $file = new UploadedFile($filePath, $originalName, 'blob', count($filePath), UPLOAD_ERR_OK, true);

count($filePath) may report error in php7.3 or upper, because count parameter must be array or countable object.

Jenky\LaravelPlupload::file is breaking the contract

According to the Jenky\LaravelPlupload\Contracts\Plupload-contract which Jenky\LaravelPlupload is implementing, the file-method should not return any value.
Actually it does return the result of Jenky\LaravelPlupload\File::process which itself is returning array.

chunk upload file name

I upload large file with chank enable after finish upload $file->getClientOriginalName() has .part suffix.

ls -l
total 1268984
-rw-r--r-- 1 root root 439463 Oct 1 21:06 jquery-ui-1.12.1.zip.part
-rw-r--r-- 1 root root 1298610430 Oct 1 21:45 jub-speechdata_AdditiveNoise_DT.tar.gz.part
-rw-r--r-- 1 root root 382474 Oct 1 21:19 plupload-2.1.9.zip.part

HTML init() function breaks after setting custom params

First of all a big thank you for this awesome package.

When playing around with the setting I discovered that when using setCustomParams throught the Plupload::make, the HTML init() function breaks.

This is because in the init() function you start with if(!$this->data). And because I used the setCustomParams function $this-data is filled before calling init().

Upon bypassing the if statement in the init() function, everything works fine again. And the custom param is added to the data.

Maybe you can update the init() function?

Greetz Erik

example full project laravel

can you give me simple implementation plupload in laravel5 full project?
im already search in google and youtube, doesnt found what i looking for. thanks

Laravel 5.4 Compatibility

In laravel 5.4 getToken() has been replaced with token()
Call to undefined method Illuminate\Session\Store::getToken()

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.