Giter Site home page Giter Site logo

jasekz / laradrop Goto Github PK

View Code? Open in Web Editor NEW
72.0 10.0 19.0 122 KB

File manager using Dropzone.js for Laravel 5.3 - 8.x - PHP

License: MIT License

PHP 25.40% JavaScript 71.75% CSS 0.74% Blade 2.11%
jquery php laravel-5-package laravel bootstrap media-library laravel5 dropzonejs demo packagist

laradrop's Introduction

This uses SoftDelete

Laradrop

Software License

This is a file manager using Dropzone.js for Laravel 5, 6, 7, 8. It provides basic functionality for managing, uploading, and deleting files.

Quick Start

  1. Follow the Installation instructions below.

    Getting errors?  Make sure you have a database set up (https://laravel.com/docs/database).
    
  2. In a view (welcome.blade.php, for example), add:

<html>
    <head>
        <title>Laradrop Demo</title>
        <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css">
        <link href="/vendor/jasekz/laradrop/css/styles.css" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet" type="text/css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" ></script>
        <script src="/vendor/jasekz/laradrop/js/enyo.dropzone.js"></script>
        <script src="/vendor/jasekz/laradrop/js/laradrop.js"></script>
    </head>
    <body>
        <div class="laradrop" laradrop-csrf-token="{{ csrf_token() }}"> </div>
    </body>
    <script>
    jQuery(document).ready(function(){
        jQuery('.laradrop').laradrop();
    });
    </script>
</html>
  1. In your .env file, add:
LARADROP_DISK_PUBLIC_URL=/uploads
LARADROP_DISK=laradrop
  1. In your config/filesystems.php, add to your disks array:
'laradrop' => [
            'driver' => 'local',
            'root' => public_path('uploads'), // will put files in 'public/upload' directory
        ],

That's it. If you have any issues or question, please feel free to open an issue.

Installation

NOTE: If you haven't set up a database yet for your app, please do that first as per Laravel docs - http://laravel.com/docs/database.

Via composer

composer require jasekz/laradrop

Then in your config/app.php add

    'Jasekz\Laradrop\LaradropServiceProvider'

to the providers array.

Then run

php artisan vendor:publish

followed by

php artisan migrate

Configuration (.env)

Laradrop uses Laravel's Filesystem mechanism (https://laravel.com/docs/filesystem) and by default will store your files in the storage/app directory. If you would like to modify this behavior, along with other default settings, you can set your .env file variables:

# s3, local, or Rackspace.  See 'Other Driver Prerequisites' at https://laravel.com/docs/filesystem.  Defaults to 'local'
LARADROP_DISK=local 

# If your files need to be web accessible, set this param.  S3, for example, would be 'https://s3.amazonaws.com/my-bucket'.  Defaults to the web root (public).
LARADROP_DISK_PUBLIC_URL=/img 

# If a thumbnail can not be generated due to incompatible file or any other reason, what image do you want to use? Defaults to 'vendor/jasekz/laradrop/img/genericThumbs/no-thumb.png'
LARADROP_DEFAULT_THUMB=/img/no-thumb.png

# Max file upload size in MB.  Defaults to 10.
LARADROP_MAX_UPLOAD_SIZE=20

# Max file size (in MB) for which thumbnail generation will be attempted.  If your server has an issue processing thumbs, you can lower this value.  Defaults to 10.
LARADROP_MAX_THUMBNAIL_SIZE=10

# Defaults to 150px.
LARADROP_THUMB_WIDTH=150

# Defaults to 150px.
LARADROP_THUMB_HEIGHT=150

# Run laradrop routes through middlware.  Defaults to none.
LARADROP_MIDDLEWARE=web

Usage

This package requires Dropzone.js, jQuery, and jQuery UI. Include these somewhere in your template:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" ></script>
<script src="/vendor/jasekz/laradrop/js/enyo.dropzone.js"></script>
<script src="/vendor/jasekz/laradrop/js/laradrop.js"></script>

By default, Laradrop is designed for Bootstrap, but it's not a requirement. Include Bootstrap and the Laradrop styles if you'd like to use it:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/vendor/jasekz/laradrop/css/styles.css" rel="stylesheet" type="text/css">

Add the html code where you'd like to implement the file manager. Note, that by default, there is no middleware assigned to the Laradrop controller, however, it you assign middleware which contains csrf protection, you must include the laradrop-csrf-token="{{ csrf_token() }}" attribute.

<div class="laradrop" laradrop-csrf-token="{{ csrf_token() }}"> </div>

Finally, bind it using jQuery:

<script>
jQuery(document).ready(function(){
    // Simplest:
    jQuery('.laradrop').laradrop();
    
    // With custom params:
    jQuery('.laradrop-custom').laradrop({
        breadCrumbRootText: 'My Root', // optional 
        actionConfirmationText: 'Sure about that?', // optional
        onInsertCallback: function (obj){ // optional 
            // if you need to bind the select button, implement here
             alert('Thumb src: '+obj.src+'. File ID: '+obj.id+'.  Please implement onInsertCallback().');
        },
        onErrorCallback: function(msg){ // optional
            // if you need an error status indicator, implement here
            alert('An error occured: '+msg);
        },
         onSuccessCallback: function(serverRes){ // optional
            // if you need a success status indicator, implement here
        }
    }); 
});
</script>

Events

Laradrop currently fires two events:

  1. Jasekz\Laradrop\Events\FileWasUploaded - this is fired after a file has been uploaded and saved.
  2. Jasekz\Laradrop\Events\FileWasDeleted - this is fired after a file is deleted.

Handlers (upload, delete, list, etc)

If you'd like to implement your own hanldlers (or extend the existing ones with your own controllers), you can do so. All you need to do, is to defined the routes to the appropriate handlers in the button attributes. This also allows you to easily have multiple handlers for different use cases, if so desired.

<div class="laradrop"
    laradrop-file-source="{{ route('yourRoute.index') }}" 
    laradrop-upload-handler="{{ route('yourRoute.store') }}"
    laradrop-file-delete-handler="{{ route('yourRoute.destroy', 0) }}"
    laradrop-file-move-handler="{{ route('yourRoute.move') }}"
    laradrop-file-create-handler="{{ route('yourRoute.create') }}"
    laradrop-containers="{{ route('yourRoute.containers') }}"
    laradrop-csrf-token="{{ csrf_token() }}"
    laradrop-allow=".pdf">
</div>

File type validations

The default implementation of accept checks the file's mime type or extension against this list. This is a comma separated list of mime types or file extensions.

Eg.: image/*,application/pdf,.psd

If the Dropzone is clickable this option will also be used as accept parameter on the hidden file input as well.

License

The MIT License (MIT). Please see License File for more information.

laradrop's People

Contributors

aurelijussaldauskas avatar jasekz avatar olegdemkiv avatar phpner avatar vikashsp 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laradrop's Issues

Boot method error

Adding this package via composer throws the following error.

Declaration of Jasekz\Laradrop\LaradropServiceProvider::boot(Illuminate\Contracts\Events\Dispatcher $events) should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot()

laradrop.js

hi
Do you have any documentation about the "laradrop.js"?

Folder image location.

EDIT: Found the answer in the laradrop.js file:

folderImage = options.folderImage ? options.folderImage : ' /vendor/jasekz/laradrop/img/genericThumbs/folder.png',

Hey :)
I'm integrating this package into a Laravel 5.4 application - I've got everything configured and working well, other than the folder image.
No matter what I have tried, I cannot change the location of this image from the vendor folder which won't load into the browser even though I can see it exists in the vendor folder.

<img src="/vendor/jasekz/laradrop/img/genericThumbs/folder.png" alt="09.08.2017 - 13:33:57">
This always returns not found. I've scoured the source files of the package and cannot find a place to change this path to a publicly accessible one (the app I am extending has a non-standard assets path above the project folder).

Could you point me to the correct place to change this path to reflect my installation config?
I have the file ready in a publicly accessible folder:
http://mydom.com/assets/vendor/jasekz/laradrop/img/genericThumbs/folder.png
So I would just need to prepend 'assets/' to the image src string.
Thanks :)

its not publishing the files needed

php artisan publishing is not pulling the files , i tried to clear configs , to clear chache , to autodump , not working at all. please fix this

How to set custom location for each user.

Hi Jasekz.
In my project, I want to give a different location for each user. I know it is easy with dropzone. In Laradrop there is no option for it. Give me a clue to fix this.
Thank you!

laravel won't pull files from files from vendor folder

as the title say laravel won't pull files I'm calling from vendor

for example



<script src="vendor/jasekz/laradrop/js/enyo.dropzone.js"></script>
<script src="vendor/jasekz/laradrop/js/laradrop.js"></script>

It says it cannot find them

EDIT: Found the problem but cannot find solution. artisan vendor:publish does not copy the public file to assets

handlers

hello I am trying to implement my own handler

It does not appear to do anything

I have tested the route independently and it works
the route is in my route file not laradrops - is that correct?

costumize index method

hello
I save my photos in a folder like this
$disk->put( 'cofeeshops/' . $coffeeshop->id . '/main/' . $movedFileName, fopen($tmpStorage . '/' . $movedFileName, 'r+'));
and save the path of photos in the photos table that I created in db like this
`

            $photo                 = new Photo();

            $photo->path           = $disk->url('cofeeshops/' . $coffeeshop->id . '/main/' . $movedFileName);

            $photo->directory      = $disk->url('cofeeshops/' . $coffeeshop->id . '/main');

            $photo->imageable_id   = $coffeeshop->id;

            $photo->imageable_type = 'coffeeshop';

            $photo->save();`

now, how can I develop my own index method?

laradrop does not support utf-8 filename saving

Hi, it is great to use laradrop package in laravel 5 project.
Unfortunately, it seems laradrop does not support utf-8 filenames. I test it with a chinese δΈ­ζ–‡.jpg, the file existing in directory seems mess. The english name is ok.
Please check it.
Thanks!~!

Is there a way to limit extensions?

Is currently a way to limit the file extensions that the user is able to upload?

Or maybe,

I can validate the extension on onInsertCallback but I don't know how to remove from the list of files to the upload.

If you could give me some hints I would appreciate it. Thanks in advance

How do I show the actual progress of the file upload?

Hello,

On the live demo, the upload progress bar seems to be consistent with the upload progress of the file, however, on my setup, the progress bar extends to the end immediately the "start upload" button is clicked.

I followed the instructions on the repo.

Please is there any extra settings to be made to show the actual progress of the file upload?

thumbnails not showing

Hello

The folder preview and thumbs were not showing.

I removed the / before vendor in the line below in laradrop.js and now the folder shows.

folderImage = options.folderImage ? options.folderImage : 'vendor/jasekz/laradrop/img/genericThumbs/folder.png',

In the database public_resource_url if I remove the leading / then the thumbnails show.

I must have a setting wrong somewhere?

Thanks for any help.

Regards
Del

Display Folder Images on Page Load

Hey Zig, Zig here :)

Could you advise me on how to have a specific folder loaded into the containers.
I've looked through laradrop.js but cannot find my way in there so well.
Also, browser inspectors show no event lisetner bound to the folder image (the image you click to show the images inside.)

I'd like to be able to offer a link so that the containers load a specific folder - meaning the images inside the folder, as if the folder had been clicked to view the contents.

I apologise if this is a trivial matter, I just figured you are helpfull and are in the best poition to give advice on this.

Thanks :)

making thumbnails rotated?

Some of my thumbnails generated are rotated 90 degrees counterclockwise. What is the factor in determining whether a thumbnail generate will be rotated?

artisan vendor:publish do not publish related files

In boot method on LaradropServiceProvider.php there is some file address than a need to publish.
when I use 'artisan vendor:publish' these files do not publish on a related directory.
please help me to fix this problem.

http://localhost/laradrop/containers NOT FOUND

Hi Jasekz,

Thank for your package. It's interesting me. But I have a problem when install it into my project. When I install and run my url it show alert "Not Found". I followed all steps to install. Thank Jasekz again. Regards,

Over Riding Laradrops Controller still calls Laradrops Controller

I have made a new controller like this

<?php 

use Jasekz\Laradrop\Http\Controllers\LaradropController;
use Input, Auth;

class UserMediaController extends LaradropController {
    
    /**
     * Upload and store new file.
     *
     * @return JsonResponse
     */
    public function store()
    {
        try {
          
            if (! Request::hasFile('file')) {
                throw new Exception(trans('err.fileNotProvided'));
            }
            
            if( ! Request::file('file')->isValid()) {
                throw new Exception(trans('err.invalidFile'));
            }
            
            /*
             * move file to temp location
             */
            $fileExt = Input::file('file')->getClientOriginalExtension();
            $fileName = str_replace('.' . $fileExt, '', Input::file('file')->getClientOriginalName()) . '-' . date('Ymdhis');
            $mimeType = Request::file('file')->getMimeType();
            $tmpStorage = storage_path();
            $movedFileName = $fileName . '.' . $fileExt;
            $fileSize = Input::file('file')->getSize();

            if($fileSize > ( (int) config('laradrop.max_upload_size') * 1000000) ) {
                throw new Exception(trans('err.invalidFileSize'));
            }
            
            Request::file('file')->move($tmpStorage, $movedFileName);
            
            $disk = Storage::disk(config('laradrop.disk'));

            /*
             * create thumbnail if needed
             */
            $fileData['has_thumbnail'] = 0;
            if ($fileSize <= ( (int) config('laradrop.max_thumbnail_size') * 1000000) && in_array($fileExt, ['jpg', 'jpeg', 'png', 'gif'])) {

                $thumbDims = config('laradrop.thumb_dimensions');
                $img = Image::make($tmpStorage . '/' . $movedFileName);
                $img->resize($thumbDims['width'], $thumbDims['height']);
                $img->save($tmpStorage . '/_thumb_' . $movedFileName);

                // move thumbnail to final location
                $disk->put('_thumb_' . $movedFileName, fopen($tmpStorage . '/_thumb_' . $movedFileName, 'r+'));
                File::delete($tmpStorage . '/_thumb_' . $movedFileName);                
                $fileData['has_thumbnail'] = 1;
                
            } 

            /*
             * move uploaded file to final location
             */
            $disk->put($movedFileName, fopen($tmpStorage . '/' . $movedFileName, 'r+'));
            File::delete($tmpStorage . '/' . $movedFileName);
            
            /*
             * save in db
             */

            if (!Auth::user()->currentTeam()){
            $eitherTeamOrUser = \Auth::user()->finduser;
            }

            elseif(Auth::user()->currentTeam()){
                $eitherTeamOrUser = \Auth::user()->currentTeam()->findteam;
            }
            $fileData['findimage'] = 1;       
            $fileData['filename'] = $movedFileName;  
            $fileData['alias'] = Input::file('file')->getClientOriginalName();
            $fileData['public_resource_url'] = config('laradrop.disk_public_url') . '/' . $movedFileName;
            $fileData['type'] = $fileExt;
            if(Input::get('pid') > 0) {
                $fileData['parent_id'] = Input::get('pid');
            }
            $meta = $disk->getDriver()->getAdapter()->getMetaData($movedFileName);
            $meta['disk'] = config('laradrop.disk');
            $fileData['meta'] = json_encode($meta);
            $file = $this->file->create($fileData);
            
            /*
             * fire 'file uploaded' event
             */
            event(new FileWasUploaded([
                'file'     => $file,
                'postData' => Input::all()
            ]));
            
            return $file;
            
        } 

        catch (Exception $e) {
            
            // delete the file(s)
            if( isset($disk) && $disk) {
                $disk->delete($movedFileName);
                $disk->delete('_thumb_' . $movedFileName);
            }
            
            return $this->handleError($e);
        }
    }

    }

Basically, I am trying to override the store method to add a findimage column in the DB. I have altered the migration made the above controller. I cannot get Auth::user() it always returns null if I make it directly in the laradropController, So I am trying to override it to have that function available to me.

 if (!Auth::user()->currentTeam()){
            $eitherTeamOrUser = \Auth::user()->finduser;
            }

            elseif(Auth::user()->currentTeam()){
                $eitherTeamOrUser = \Auth::user()->currentTeam()->findteam;
            }
            $fileData['findimage'] = 1;

But this does not overwrite the laradropsController.

I have added these routes

//User Media Files 
Route::get('mediaIndex', 'UserMediaController@index');
Route::post('mediaStore', 'UserMediaController@store');
Route::post('mediaDestroy', 'UserMediaController@destroy');
Route::post('mediaMove', 'UserMediaController@move');
Route::post('mediaCreate', 'UserMediaController@create');

And instantiate the laradrops like this

<div class="laradrop"
              laradrop-file-source="/mediaIndex" 
              laradrop-upload-handler="/mediaStore"
              laradrop-file-delete-handler="/mediaDestroy"
              laradrop-file-move-handler="/mediaMove"
              laradrop-file-create-handler="/mediaCreate"
              laradrop-csrf-token="bVgziBueIHaJqYdIruMg5pW2tISSEFMs9Qc5K7AY">
          </div>

Any idea why it doesnt hit my new controller?

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.