PHP code example of mykemeynell / filepreview

1. Go to this page and download the library: Download mykemeynell/filepreview 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/ */

    

mykemeynell / filepreview example snippets


$fileName = '/path/to/file.pdf';
$preview = mykemeynell\FilePreview\FilePreview::fromPath($fileName);

echo $preview->preview()->stream();

FilePreview::addHandler('application/pdf', function ($preview, $file) {
    /** @var \mykemeynell\FilePreview\FilePreview $preview */
    /** @var \mykemeynell\FilePreview\FileSystem\File $file */

    // $content = ...=

    $preview->setContentTypeHeader('image/jpg');
    $preview->setContent($content);
    
    return $preview;
});