Package Data | |
---|---|
Maintainer Username: | recca0120 |
Maintainer Contact: | recca0120@gmail.com (recca0120) |
Package Create Date: | 2015-12-30 |
Package Last Update: | 2024-04-11 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-13 15:11:00 |
Package Statistics | |
---|---|
Total Downloads: | 5,555 |
Monthly Downloads: | 60 |
Daily Downloads: | 3 |
Total Stars: | 79 |
Total Watchers: | 4 |
Total Forks: | 18 |
Total Open Issues: | 0 |
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"
}
}
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"
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);
});
}
}
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();
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();