Code Monkey home page Code Monkey logo

laravel-plupload's Introduction

laravel-plupload

Laravel plupload support.

Handeling chunked uploads.

Installation

Install using composer

composer require jildertmiedema/laravel-plupload

Add the provider to config/app.php

'providers' => [
    JildertMiedema\LaravelPlupload\LaravelPluploadServiceProvider::class,
]

If you want to use te build in builder insert the facade

'aliases' => array(
    'Plupload' => JildertMiedema\LaravelPlupload\Facades\Plupload::class,
),

To publish the assets:

php artisan vendor:publish

Receiving files

Use this route to receive a file on the url /upload. Of course you can place this is a controller.

Route::post('/upload', function()
{
    return Plupload::receive('file', function ($file)
    {
        $file->move(storage_path() . '/test/', $file->getClientOriginalName());

        return 'ready';
    });
});

Sending files

There are 3 ways to send files with this plugin.

1. Use default plupload html

Use the examples found on the plupload site.

Issues

If you are encountering a Token Mismatch Exception;

TokenMismatchException in VerifyCsrfToken.php line 53:

add in your blade file

<meta name="csrf-token" content="{{ csrf_token() }}">

in your JS file, add

headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },

Eg:

$('.js-uploader').pluploadQueue({

	// General settings
	runtimes: 'html5,flash,silverlight,html4',
	url: '/upload/',
	chunk_size: '200kb',
    rename: false,
    dragdrop: true,
	// add X-CSRF-TOKEN in headers attribute to fix this issue
	headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
	// add more overrides; see documentation...

});

2. Simple plupload builder

To use the builder for creating send form you can use this function:

echo Plupload::make([
    'url' => 'upload',
    'chunk_size' => '100kb',
]);

Note: The options given to the make function are found on in the pluload documentation.

3. Extended plupload builder

echo Plupload::init([
    'url' => 'upload',
    'chunk_size' => '100kb',
])->withPrefix('current')->createHtml();

Alternatives

Other packages supporting plupload:

laravel-plupload's People

Contributors

aginev avatar askippers avatar gilbitron avatar jildertmiedema avatar laravel-shift avatar liorocks avatar michalmrzyk avatar piroz avatar resoftw avatar stevebauman avatar tigitz avatar umarmw 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-plupload's Issues

Stopping upload and selecting another file

Hi!
Im trying to stop current upload and then I select another file and begin upload. Backend just merge this two files.
How to prevent this?

upload.stop(); upload.removeFile(upload.files[0]); $('#filelist').html(''); upload.destroy(); upload = uploader(); upload.init();

I can't get it to work in a controller

This may sound dumb, but i am very new to laravel and i'm wondering how to put this piece of code:

return Plupload::receive('file', function ($file)
{
    $file->move(storage_path() . '/test/', $file->getClientOriginalName());

    return 'ready';
});

in a controller. Any help would be appreciated

Dealing with laravel storage

Hello,

I having some troubles dealing with local storage. As mentioned in L5 docs:

The put method may be used to store a file on disk. You may also pass a PHP resource to the put method, which will use Flysystem's underlying stream support. Using streams is greatly recommended when dealing with large files:

But at the moment the very last part of the files is written at the storage or just a few KBs

return Plupload::receive('file', function (UploadedFile $file) {
    $storage = Storage::disk('uploads')->put('test.mp3', $file);

    return 'ready';
});

Any ideas how to figure out this are very appreciated!

Regards

Nasko

uploading as {FileName}.part

I have an issue. It's uploading like {FileName}.part .I've checked php.ini and nothing wrong. I guess there is a problem with :

if ($chunk == $chunks - 1) { $file = new UploadedFile($filePath, $originalName, 'blob', filesize($filePath), UPLOAD_ERR_OK, true); $result = $closure($file); @unlink($filePath); }

I think UploadedFile is not working for some reason but I didn't understand. Can you help me ?

{"jsonrpc":"2.0","result":null}

Hi,

I'm trying to track this, but can't find where this might fail.

Default usage:

# Upload file route
Route::post( 'upload', function()
{
    return \Plupload::receive('file', function ($file)
    {
        $file->move(storage_path() . '/test/', $file->getClientOriginalName());
        return 'ready';
    });
} );

POST body:

Content-Disposition: form-data; 
name="name" 2015-chevrolet-suburban-full-size-suv-mo-exterior-1480x551.jpg 
Content-Disposition: form-data; name="chunk" 0  
Content-Disposition: form-data; name="chunks" 1
Content-Disposition: form-data; name="file"; 
filename="2015-chevrolet-suburban-full-size-suv-mo-exterior-1480x551.jpg" 
Content-Type: image/jpeg 
...

Any thoughts?

Incomplete attachment to the original file

If you send a file in pieces and there is a problem in the middle of the work and the submission is incomplete, a part file will be stored on the server.
Now, if you send the file completely again, it will connect the pieces in the server section, and in addition to the pieces of the original file, the incomplete piece that already exists will be added to the file, and the length of the file will be longer than the original file.

Postinit funtion

i am trying to get a postinit function in the facade maker, but it escape the function
Plupload::init([
'init'=> "{PostInit: function() {document.getElementById('filelist').innerHTML = '';document.getElementById('uploadfiles').onclick = function() {uploader.start();return false;};
}}",

If i remove the "" it fails because, the code is wrong, but how can I implement the Postinit function?

Laravel 5.0 Support

Any thought's on updating this package for 5.0? Looking through your code, I don't see any dependency issues using illuminate/support: ~5.0 over 4.2. Is allowing installation of this package with either versions possible through composer? I know Laravel 5.0 is in it's infancy at the moment, but I'd definitely like to try this package out with it.

Problem with Laravel 5.1

Hello,

This packages depends on "Illuminate\Http\UploadedFile" Class [Receiver.php, appendData()],

but this Laravel Class was only created on Laravel 5.3, so, this packages breaks when used on Laravel 5.1.

I could use this by replacing these files:
LaravelPluploadServiceProvider.php
Manager.php
Receiver.php

On the new Receiver.php I used the "Symfony\Component\HttpFoundation\File\UploadedFile"

Thanks.

Multiple instances for repeater fields

Hi, found this plugin very easy to setup and nicely ready for production. We've made a form for our client with a single attachment block with multiple attachments facilities.

But now client wants to bind Some text/select choice with each of the files individually so that they provide title for each of the file or they can group files etc. So I choose repeater fields with using jQuery Dynamic Form and Plupload for each of the row. The thing should be something like this:
dynamic form for repeater fields with plupload

I found a solution, I think, not yet tried.

But your plugin might not ready for such things:

  1. It's generating UI widget by default and I cannot trigger a Core view for each of the fields
  2. You are using id for plupload selector and id selector for iterating fields failed me to select files in newly generated plupload instances

So what I got is:
dynamic form for repeater fields with plupload

And plupload simply isn't working for multiple instances where it's triggered on an ID.

erorr while installing

i have a problem when install this package, there is my problem

Using version ^0.7.1 for jildertmiedema/laravel-plupload
./composer.json has been updated
Running composer update jildertmiedema/laravel-plupload
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires jildertmiedema/laravel-plupload ^0.7.1 -> satisfiable by jildertmiedema/laravel-plupload[v0.7.1].
    - jildertmiedema/laravel-plupload v0.7.1 requires illuminate/support ^8.0 -> found illuminate/support[v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

please help me about this problem
Screenshot_77

Laravel 5.1.25

Hi!

I'me having the following problem.

When you have the chunksize in plupload on lets say "1mb", then you cannot upload files larger the 1mb for laravel-plupload will not receive the file or something..

There is no error, you just don't get into the nameless function

$return = Plupload::receive('file', function ($file) { 
  //Will not come here when upload is larger then chunksize!
});

Running:
nginx - 1.62

client_max_body_size 500M;

hhvm - 3.6.1

upload_max_filesize = 1024M
post_max_size = 1024M

Kind regards,
Raymond

Laravel 8 is now mandatory

Hi,

I've tried to add your package on my project which has Laravel 5.8 installed.
Apparently, your package requires illuminate/support ^8.0 which also requires laravel/framework 8.

Here is the error log :

  • jildertmiedema/laravel-plupload v0.7.1 requires illuminate/support ^8.0 -> satisfiable by laravel/framework[8.x-dev], illuminate/support[8.x-dev, v8.0.0, v8.0.1, v8.0.2, v8.0.3, v8.0.4, v8.1.0, v8.2.0, v8.3.0].

Is there a way to use your package with Laravel version 5.8?

Thank you for your help.
Regards.

PHP 7.2 throw the sizeof warning

When uploadfile under PHP 7.2 , throw the sizeof warning:

sizeof(): Parameter must be an array or an object that implements Countable

File:

vendor\jildertmiedema\laravel-plupload\src\JildertMiedema\LaravelPlupload\Receiver.php

Line: 73

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

I found this:

http://www.php.net/count

7.2.0 count() will now yield a warning on invalid countable types passed to the array_or_countable parameter.

Waiting Help,Thanks!

Can you create a tag from a specific reference please?

Hi,

The one of my old project with using laravel 4.2 has been configured as dev-master.

dev-master version is referenced to 1b85aa6, because v0.2.1 version has a few bugs. I would be happy if it is possible to create a new tag this reference (1b85aa6) as v0.2.2 or something.

Thanks.

Issue "unknown error" While Uploading image in laravel 8

Symfony\Component\HttpFoundation\File\Exception\FileException: The file "image.png" was not uploaded due to an unknown error. in file /var/www/html/laravel_common_web/vendor/symfony/http-foundation/File/UploadedFile.php on line 213

i am uploading right extension image and right size image which we have specified.

can you help to get what's the error

Error #-200: HTTP Error.

Locally, this pluploader works fine. On my prod server it works for files less then 1 MB, for everything else it fails like this:

image

Although it shows 100% in the progressbar, same named files are available in plupload folder, but they have size 0kb.

This is how it looks in inspection window:
image

Problem with UploadedFile from Symfony new Http-Foundation

The construct of UploadFile do not accept the filesize anymore.

So, the method receiveChunks should instance the new UploadedFile, without passing the filesize attribute:
$file = new UploadedFile($filePath, $originalName, 'blob', UPLOAD_ERR_OK, true); /sizeof => filesize : fix for php 7.2/

Customize $scriptUrl

I had to change:
private $scriptUrl = '//localhost:8888/saysw/public/vendor/jildertmiedema/laravel-plupload/js/plupload.full.min.js';

from a default value.

And I had to comment out Laravel's
<!--script src="{{ asset('js/app.js') }}" defer></script-->

it both was not compatible with Laravel version 5.7

[Suggestion] Use Illuminate\Http\UploadedFile instead of Symfony\Component\HttpFoundation\File\UploadedFile

Why not use Illuminate\Http\UploadedFile instead of Symfony\Component\HttpFoundation\File\UploadedFile in Receiver.php line 7?

With that, you'll have more functions on $file instance in the receive method of plupload, such as store, storeAs and etc. https://laravel.com/docs/5.3/filesystem

Route::post('/upload', function()
{
    return Plupload::receive('file', function (UploadedFile $file)
    {
        $file->store('path_to_dir');
        return 'ready';
    });
});

I would make a pull request, but, not sure if this package is still under maintenance.
Plus it's only one line need to be changed and after running unit tests on this package I ended up with errors, which was caused by Mocking in my mind.

Input sanitization ?

How are file/chunk names sanitized ? Is this package protected from directory traversal attacks ?

This seems not working on a live server

This package seems not working on a live server, but locally it's working. There is no additional info in laravel.log

  • Laravel version: 5.2
  • Laravel-Plupload version: 0.3.1

On a live server I'm using the following:

  • Nginx Server(Ubuntu 16.04.4 LTS) - Digital Ocean
  • PHP Version: 7.0

Locally, I'm using the following:

  • Nginx Server(Laravel valet)
  • PHP Version: 7.0

I did all necessary configurations on the server including setting max file upload size and max post size in php.ini. I also set max client body size.

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.