Giter Site home page Giter Site logo

maymeow / cakephp-fileupload Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 69 KB

๐Ÿ†™ File Upload plugin for CakePHP. This is mirror from my dev server. Package is available on packagist and on my dev serers's composer.

Home Page: https://wiki.0x0.sk/en/cake-php/FileUpload

License: MIT License

PHP 97.64% Dockerfile 2.36%
cakephp-plugin cakephp4 file-upload hacktoberfest

cakephp-fileupload's Introduction

๐Ÿ†™ FileUpload plugin for CakePHP

โš ๏ธ This is readme for version 2.x. For 1.x go to v1.1.2 release.

๐Ÿ›‘ Breaking changes (read before use)

Version 2.x is not compatibile with cakephp lower than 5.x and it is not backward compatibile with previous releases of this plugins.

  • S3 storage support was removed (will be added in future relases)
  • Bunny CND storage support was added
  • All components and Managers was rewritten.

And supported actions are upload and download.

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

๐Ÿ˜ From packagist

composer require maymeow/file-upload "^2.0.0"

Usage

Add configuration somewhere to your config files

'Storage' => [
    'defaultStorageType' => env('STORAGE_DEFAULT_STORAGE_TYPE', 'local'),
    'local' => [
        'managerClass' => LocalStorageManager::class,
        'storagePath' => env('STORAGE_LOCAL_STORAGE_PATH', ROOT . DS . 'storage' . DS),
    ],
    'bunny' => [
        'managerClass' => BunnyStorageManager::class,
        'cdnDomain' => env('BUNNY_STORAGE_CDN_DOMAIN', ''), // your cnd url
        'region' => env('BUNNY_STORAGE_REGION', ''), // region, empty is DE
        'baseHostName' => 'storage.bunnycdn.com', // base host name not changeable
        'storageZone' => env('BUNNY_STORAGE_ZONE', ''), // your storage zone name
        'storageZonePath' => env('BUNNY_STORAGE_ZONE_PATH', ''), // folder in zono
        'accessKey' => env('BUNNY_STORAGE_ACCESS_KEY', ''), // API key for write access
    ]
]

For bunny cdn minimal configuration is to have folowing keys configured

BUNNY_STORAGE_ACCESS_KEY=
BUNNY_STORAGE_CDN_DOMAIN=
BUNNY_STORAGE_ZONE=

If you need/want nginx to server your static files without PHP set STORAGE_LOCAL_STORAGE_PATH location to whe webroot folder.

Load plugin with adding

$this->addPlugin('FileUpload'); // in your Application.php bootstrap function

or you can add your plugin with plugins.php config file

return [
    // .. your other plugins
    'FileUpload' => [],
];

Loading components

$config = Configure::read('Storage.local'); // or Storage.bunny

// or by setting it with .env STORAGE_DEFAULT_STORAGE_TYPE
$storageType = Configure::read('Storage.defaultStorageType');
$config = Configure::read('Storage.' . $storageType); 

$this->loadComponent('FileUpload.Upload', $config);
$this->loadComponent('FileUpload.Download', $config);

Uploading files

$file = $this->Upload->getFile($this);
// do something with file

// store your file name in database
$file->getFileName(); // sanitized file name - with removed restricted characters in the name
$file = $this->Download->getFile($resource->name);
// do something with file

๐Ÿ“ Note that the function above will read content of file and you then need to use response to push it to the viewer. If you want to do it without using PHP you will need to get URL of file and if you using local storage manager your folder need to be in webrootfolder.

$file->get('storagePath'); // local: /patht/to/sorage or bunny: https://cdn.your.tld/path/to/folder/
// combine it with filename from your database go download it

License

MIT

cakephp-fileupload's People

Contributors

maymeow avatar

Watchers

 avatar  avatar  avatar  avatar

cakephp-fileupload's Issues

delete file and record both

Using the standard CakePHP code, the delete will handle the record in the MySQL table, but not the file. How do you do both? This should be in the documentation.

Call to a member function getClientMediaType() on string

I followed the few instructions, and when I attempt to run the code, this is the error I get.

Perhaps what I am missing is something in the ./templates//add.php page that actually prompts the user for the file to upload. Can you add that code to the readme?

AWS s3 support

Implement ability to store and retrieve files from S3 compatible storage. For development purposes you can use Minio server

File : vendor/maymeow/file-upload/src/Storage/LocalStorageManager.php

File : vendor/maymeow/file-upload/src/Storage/LocalStorageManager.php

Function : move
$fileObject->moveTo($this->configuration->getConfig('storagePath') . $fileObject->getClientFilename());

this line is giving an error. if I print the path it is "storage/agent-registration-2.jpg"
As I said above my storage folder is parallel to src and webroot folder,

Originally posted by @TechnoPHP in #7 (comment)

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.