itskodinger / midia

Simple Media manager for your Laravel project
MIT License
139 stars 35 forks source link

Enables multiple/custom directories #2

Closed captainspain closed 6 years ago

captainspain commented 6 years ago

This way you could use custom directories.

Usage config/midia.php

<?php

return [
    // Target directory
    'directory' => storage_path('media'),
    // For URL (e.g: http://base/media/filename.ext)
    'directory_name' => 'media',
    'prefix' => 'midia',
    // Multiple target directories
    'home_directory' => storage_path('media/site/home'),
    // It's also possible to change the prefix 'media', but you should create a new symlink.
    'home_directory_name' => 'media/site/home',
];

In your view:

<link rel="stylesheet" href="{{asset('vendor/midia/midia.css')}}">
<link rel="stylesheet" href="{{asset('vendor/midia/dropzone.css')}}">

<div id="midia-inline"></div>

<script src="{{asset('vendor/midia/dropzone.js')}}"></script>
<script src="{{asset('vendor/midia/midia.js')}}"></script>
<script>
        $("#midia-inline").midia({
            inline: true,
            base_url: '{{url('')}}',
            directory: '{{ config('midia.home_directory') }}',
            directory_name: '{{ config('midia.home_directory_name') }}'
        });
</script>
nauvalazhar commented 6 years ago

Hi @captainspain, thanks for your contribution. Can you give me more explanation for this? Regards

captainspain commented 6 years ago

Hi @nauvalazhar, You are welcome, I like this package (simple and does what it says) :+1:

The reason for this PR: I was creating a very simple CMS, where I use this package for media upload. But I wanted to use different folders for different pages. In the normal setup you can only select one path, and now I can add as many paths I would like to. So if you don't specify the directory and directory_name it will use the default config as it was, like:

<script>
        $("#midia-inline").midia({
            inline: true,
            base_url: '{{url('')}}'
        });
</script>

This will use the directory, directory_name from midia config file (default). But if you specify the directory and directory_name it will use the custom paths:

<script>
        $("#midia-inline").midia({
            inline: true,
            base_url: '{{url('')}}',
            directory: '{{ config('midia.home_directory') }}',
            directory_name: '{{ config('midia.home_directory_name') }}'
        });
</script>

If you specify it like this it will add the GET params to the XHR request so the controller knows to use an other path. You can also add a custom path without adding it to your config, but I prefer it to do it in config.

Regards.

nauvalazhar commented 6 years ago

Whoa, nice work. I will merge your PR for a better library. Thanks for your contribution.