PHP code example of vish4395 / laravel-file-viewer

1. Go to this page and download the library: Download vish4395/laravel-file-viewer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vish4395 / laravel-file-viewer example snippets


use Vish4395\LaravelFileViewer\LaravelFileViewer;

class FilePreviewController extends Controller
{
    public function show(string $fileName)
    {
        return LaravelFileViewer::show(
            fileName: $fileName,
            filePath: $fileName,
            fileUrl: asset('storage/' . $fileName),
            disk: 'public',
            fileData: [
                ['label' => 'Uploaded by', 'value' => 'Jane Doe'],
                ['label' => 'Department',  'value' => 'Finance'],
            ]
        );
    }
}

Route::get('/files/{fileName}', [FilePreviewController::class, 'show']);

return [
    // Default storage disk used when no disk is passed to ::show()
    'default_disk' => env('FILE_VIEWER_DISK', 'public'),

    // Fall back to Google Docs Viewer for unsupported file types
    'google_viewer_fallback' => env('FILE_VIEWER_GOOGLE_FALLBACK', false),

    // Toolbar button visibility
    'toolbar' => [
        'download'        => env('FILE_VIEWER_TOOLBAR_DOWNLOAD', true),
        'open_in_new_tab' => env('FILE_VIEWER_TOOLBAR_NEW_TAB', true),
        'copy_link'       => env('FILE_VIEWER_TOOLBAR_COPY_LINK', true),
        'fullscreen'      => env('FILE_VIEWER_TOOLBAR_FULLSCREEN', true),
    ],
];
bash
php artisan vendor:publish --provider="Vish4395\LaravelFileViewer\LaravelFileViewerServiceProvider" --tag=assets
bash
php artisan vendor:publish --provider="Vish4395\LaravelFileViewer\LaravelFileViewerServiceProvider" --tag=config
bash
php artisan vendor:publish --provider="Vish4395\LaravelFileViewer\LaravelFileViewerServiceProvider" --tag=views