digilive/file-streamer

Stream a file or serve a file as (resumeable) download

v1.0.0 2022-10-02 09:54 UTC

This package is auto-updated.

Last update: 2024-04-30 00:34:07 UTC


README

GitHub release License

This library serves a file according to the headers which are sent with a http request. It supports resumable downloads or streaming the content of a file to a client.

If you have any questions, comments or ideas concerning this library, please consult the code documentation at first. Create a new issue if your concerns remain unanswered.

Features

  • Inline disposition.
  • Attachment disposition.
  • Serve a complete file.
  • Serve a single byte range of a file.
  • Serve multiple byte ranges of a file.
  • Set a custom mimetype.

Requirements

  • PHP ^7.4
  • ext-fileinfo *

Installation

The preferred method is to install the library with Composer.

> composer require digilive/file-streamer:^1

Set the version constraint to a value which suits you best.
Alternatively you can download the latest release from GitHub.

Example use

<?php

use DigiLive\FileStreamer\FileStreamer;

// Use composer's auto loader.
$requiredFile = 'Path/To/vendor/autoload.php';

// Or include the library manually.
// $requiredFile = 'Path/To/FileStreamer.php';

require_once $requiredFile;

// Instantiate the library.
$fileStreamer = new FileStreamer('Path/To/File/To/Serve.ext');
// Set inline disposition if wished.
$fileStreamer->setInline();
$fileStreamer->start();
// Execution of PHP will terminate when FileStreamer::start() is finished.