PHP code example of mostafaznv / php-x-sendfile

1. Go to this page and download the library: Download mostafaznv/php-x-sendfile 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/ */

    

mostafaznv / php-x-sendfile example snippets


'providers' => [
  Mostafaznv\PhpXsendfile\PhpXsendfileServiceProvider::class,
],

'aliases' => [
  'Recaptcha' => Mostafaznv\PhpXsendfile\Facades\PhpXsendfile::class,
]



namespace App\Controllers;

use Mostafaznv\PhpXsendfile\PhpXsendfile;

class DownloadController
{
    public function quickExample()
    {
        $path = '/files/Sample.mp4';

        $xSendFile = new PhpXsendfile();
        $xSendFile->download($path);
    }

    public function completeExample()
    {
        $path = '/files/Sample.mp4';
        // or full path
        $path = public_path('files/Sample.mp4');

        // optional
        $config = [
            'server' => null,
            
            'cache'                 => true,
            'cache-control-max-age' => 2592000
        ];

        // set extra headers (optional)
        $headers = [
            'Header-Name' => 'Header-Value' // header('Header-Name: Header-Value')
        ];

        // set downloaded filename (optional, nullable)
        $fileName = 'LargeVideoFile.mp4';

        $xSendFile = new PhpXsendfile($config);
        $xSendFile->setHeader($headers)->download($path, $fileName);
    }
}




namespace App\Http\Controllers;

use Mostafaznv\PhpXsendfile\Facades\PhpXsendfile; // or use PhpXsendfile;

class DownloadController extends Controller
{
    public function quickExample()
    {
        $path = public_path('files/zip.zip');

        PhpXsendfile::download($path);

        // or
        
        app('x-sendfile')->download($path);
    }

    public function completeExample()
    {
        $path = public_path('files/zip.zip');

        // set extra headers (optional)
        $headers = [
            'Header-Name' => 'Header-Value' // header('Header-Name: Header-Value')
        ];

        // set downloaded filename (optional, nullable)
        $fileName = 'LargeVideoFile.mp4';

        PhpXsendfile::setHeader($headers)->download($path, $fileName);
    }
}
shell
php artisan vendor:publish --provider="Mostafaznv\PhpXsendfile\PhpXsendfileServiceProvider"