Giter VIP home page Giter VIP logo

upload's Introduction

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();

upload's People

Contributors

recca0120 avatar

Watchers

 avatar

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.