Noah Telussa
Noah Telussa

Reputation: 151

Laravel unisharp file manager combine file and image manager

Last week I discovered the Unisharp file manager plugin. After a lot of tweaking on the plugin i managed to get the plugin working in my browser without opening a new page (Like you supposed to get with the plugin)

A view from my browser: enter image description here enter image description here

The first image are my images that i have uploaded and the second picture is my files that i have uploaded.

Now my problem is that I'am trying to get them both in 1 file manager so the files and images are together in one file manager.

I have tried to tweak the config/lfm.php, public/photos/ into public/files/ like you see here below

enter image description here

just like where the files are linked to but when i do that the images and files that i have previous uploaded wont load

enter image description here

So if you got any suggestions on how to combine the files and images manager together or got a other suggestion for an other plugin it would be great,

Greetings,

Noah

Upvotes: 1

Views: 4276

Answers (2)

Noah Telussa
Noah Telussa

Reputation: 151

So after seeing the comment @Stream Huang. I manage to get it working, its true that the image got thumbs and the files like a pdf dont.

First thing that I did was at the UploadController@Upload change

if ('Images' === $this->file_type) {
    $this->makeThumb($dest_path, $new_filename);
}

After that I made a variable that get the extension/file name of the file that you just uploaded and filter it on images.

$fileName = $file->getMimeType();

if ($fileName == "image/jpeg" || $fileName == "image/png") {
    $this->makeThumb($dest_path, $new_filename);
}

In the ItemController I added a [$key] to the array

ItemController@getFileInfos (original)

$file_info[$key] = [
    'name'      => $file_name,
    'size'      => $file_size,
    'created'   => $file_created,
    'type'      => $file_type,
    'icon'      => $icon,
];

to:

$file_info[$key] = [
    'name' => $file_name,
    'size' => $file_size,
    'created' => $file_created,
    'type' => $file_type,
    'icon' => $icon,
    'title' => $file_data[$key]->title,
    'alt' => $file_data[$key]->alt,
    'id' => $file_data[$key]->id,
];

The title,alt and id are comming from the database (When I upload a image I first need to enter a title, alt and the image before uploading it. The data that I have I store it in the database so I can use that data for like a news article).

I also changed a couple of blades mainly the item and the index

item.blade.php (original)

@if($type == 'Images')
    <img id="{{ $file_name }}" src="{{ asset($thumb_src) }}" class="pointer" onclick="useFile('{{ $file_name }}')">
@else
    <i class="fa {{ $file['icon'] }} fa-5x" style="height:200px;cursor:pointer;padding-top:60px;" onclick="useFile('{{    $file_name }}')"></i>
@endif

item.blade.php (edit)

$file_name = $file_info[$key]['name'];
$filebroken = substr($file_name, -3);
$extension = array_pop($filebroken);

The file_info[$key]['name'] is a file name that is getting from the database just like image.jpg , i get the last 3 characters of the name so its most likely .jpg or .png if its a image.

After that I'm checking if $extension variable is a jpg or a png, else i make it a icon of it.

@if($extension == 'png' || $extension == 'jpg')
    <img id="{{ $file_name }}" src="{{ asset($thumb_src) }} class="pointer" onclick="useFile('{{ $file_name }}')">
@else
    <i class="fa {{ $file['icon'] }} fa-5x" onclick="useFile('{{ $file_name }}')"></i>
@endif

Upvotes: 0

Stream Huang
Stream Huang

Reputation: 336

Full disclosure: I am the package maintainer, work for UniSharp.

You have done it well! The only problem is, images have thumbs while files don't(files show icons). When the get parameter "type" is set to be "Image"(link here), files and images will show but the thumbs of files will left broken.

Solution: You can set default image like below, in case of broken file thumbs.

<img onclick="useFile('{{ $file_name }}')" onError="this.src='/img/default.jpg'">

Upvotes: 1

Related Questions