recca0120 / upload by recca0120

Ajax Upload Large File Support jQuery-File-Upload, FileApi, Plupload, Support framework Laravel 5
4,581
77
4
Package Data
Maintainer Username: recca0120
Maintainer Contact: recca0120@gmail.com (recca0120)
Package Create Date: 2015-12-30
Package Last Update: 2024-03-02
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-10 03:09:41
Package Statistics
Total Downloads: 4,581
Monthly Downloads: 56
Daily Downloads: 0
Total Stars: 77
Total Watchers: 4
Total Forks: 18
Total Open Issues: 1

Donate

Pure Ajax Upload And for Laravel 5 (Support jQuery-File-Upload, FileApi, Plupload)

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License Monthly Downloads Daily Downloads Scrutinizer Code Quality Code Coverage

Features

Installing

To get the latest version of Laravel Exceptions, simply require the project using Composer:

composer require recca0120/upload

Instead, you may of course manually update your require block and run composer update if you so choose:

{
    "require": {
        "recca0120/upload": "^1.7"
    }
}

Laravel 5

Include the service provider within config/app.php. The service povider is needed for the generator artisan command.

'providers' => [
    ...
    Recca0120\Upload\UploadServiceProvider::class,
    ...
];

publish

artisan vendor:publish --provider="Recca0120\Upload\UploadServiceProvider"

How to use

Controller


use Illuminate\Http\JsonResponse;
use Recca0120\Upload\UploadManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class UploadController extends Controller
{
    public function upload(UploadManager $manager)
    {
        $driver = 'plupload'; // or 'fileapi'
        $inputName = 'file'; // $_FILES index;

        return $manager->driver($driver)->receive($inputName);

        // or
        return $manager
            ->driver($driver)
            ->receive($inputName, function (UploadedFile $uploadedFile, $path, $domain, $api) {
                $clientOriginalName = $uploadedFile->getClientOriginalName();
                $clientOriginalExtension = strtolower($uploadedFile->getClientOriginalExtension());
                $basename = pathinfo($uploadedFile->getBasename(), PATHINFO_FILENAME);
                $filename = md5($basename).'.'.$clientOriginalExtension;
                $mimeType = $uploadedFile->getMimeType();
                $size = $uploadedFile->getSize();
                $uploadedFile->move($path, $filename);
                $response = [
                    'name' => pathinfo($clientOriginalName, PATHINFO_FILENAME).'.'.$clientOriginalExtension,
                    'tmp_name' => $path.$filename,
                    'type' => $mimeType,
                    'size' => $size,
                    'url' => $domain.$path.$filename,
                ];

                return new JsonResponse($response);

            });
    }
}

Factory

use Recca0120\Upload\Receiver;
use Illuminate\Http\JsonResponse;

require __DIR__.'/vendor/autoload.php';

$config = [
    'chunks' => 'path_to_chunks',
    'storage' => 'path_to_storage',
    'domain' => 'http://app.dev/',
    'path' => 'web_path'
];

$inputName = 'file';
$storagePath = 'relative path';
$api = 'fileapi'; // or plupload

Receiver::factory($config, $api)->receive($inputName)->send();

Standalone


use Recca0120\Upload\Receiver;
use Recca0120\Upload\FileAPI;
use Recca0120\Upload\Plupload;
use Illuminate\Http\JsonResponse;

require __DIR__.'/vendor/autoload.php';

$config = [
    'chunks' => 'path_to_chunks',
    'storage' => 'path_to_storage',
    'domain' => 'http://app.dev/',
    'path' => 'web_path'
];

$inputName = 'file';
$storagePath = 'relative path';

// if use Plupload, new Recca0120\Upload\Plupload
$receiver = new Receiver(new FileAPI($config));
// save to $config['base_path'].'/'.$storagePath;
$receiver->receive($inputName)->send();