2017 © Pedro Peláez
 

library http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

image

diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  • Wednesday, September 13, 2017
  • by diversen
  • Repository
  • 3 Watchers
  • 26 Stars
  • 18,106 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 3 Open issues
  • 16 Versions
  • 46 % Grown

The README.md

HTTP send file

Sends a file with support for (multiple) range requests. It is able to throttle the download and adds an etag to the request. It is quite small and simple., (*1)

Install

With composer add to your "require" section:, (*2)

composer require diversen/http-send-file

Usage example:, (*3)


use Diversen\Sendfile; $s = new Sendfile(); // if you don't set type - we will try to guess it $s->setContentType('application/epub+zip'); // if you don't set disposition (file name user agent will see) // we will make a file name from file $s->setContentDisposition('test.epub'); // Expires header. Default is a date in the past $s->setExpires(3600); // chunks of 40960 bytes per 0.1 secs // if you don't set this then the values below are the defaults // approx 40960 bytes per sec $s->throttle(0.1, 40960); // file $file = '/some/dir/test.epub'; // send the file try { $s->send($file); } catch (\Exception $e) { echo $e->getMessage(); }

So you could just do like this:, (*4)


use Diversen\Sendfile; $s = new Sendfile(); // file $file = '/some/dir/test.epub'; // send the file try { $s->send($file); } catch (\Exception $e) { echo $e->getMessage(); } // but check the headers if it is not // working as expected as the guessing // of content-type does not always work // correctly.

Without sending content-disposition header:, (*5)


// without sending content-disposition header // 2. param = false try { $s->send($file, false); } catch (\Exception $e) { echo $e->getMessage(); }

Test notes

Build image:, (*6)

docker build -t php-apache2 .

Run the docker image:, (*7)

docker run -d -p 8080:80 -v $(pwd):/var/www/html --name test-send-file php-apache2

Enable autoloading:, (*8)

composer install

Go to the browser at: http://localhost:8080/test, (*9)

Or use curl, e.g.:, (*10)

Test that download is resumable:, (*11)

curl -v -L -C - -o test.pdf http://localhost:8080/test/slow_download.php

Credits

Much of the code is taken (and rewritten) from here:, (*12)

http://w-shadow.com/blog/2007/08/12/how-to-force-file-download-with-php/, (*13)

The process is nicely explained here:, (*14)

http://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/, (*15)

MIT © Dennis Iversen, (*16)

The Versions

13/09 2017

dev-master

9999999-dev http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  Sources   Download

MIT BSD-3-Clause

file http download throttle resume

13/09 2017

v2.0.3

2.0.3.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  Sources   Download

MIT

file http download throttle resume

13/09 2017

v2.0.2

2.0.2.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  Sources   Download

MIT

file http download throttle resume

13/09 2017

v2.0.1

2.0.1.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

13/09 2017

v2.0.0

2.0.0.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

23/11 2016

v1.0.91

1.0.91.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is also able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

13/09 2016

dev-revert-6-master

dev-revert-6-master http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

25/08 2016

v1.0.9

1.0.9.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

05/08 2015

v1.0.7

1.0.7.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

05/08 2015

v1.0.8

1.0.8.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

05/08 2015

v1.0.6

1.0.6.0 http://github.com/diversen/http-send-file

Sends a file to a client, with support for (multiple) range requests. It is able to throttle the download.

  Sources   Download

BSD-3-Clause

file http download throttle resume

08/05 2015

v1.0.5

1.0.5.0

  Sources   Download

01/04 2015

v1.0.4

1.0.4.0

  Sources   Download

01/04 2015

v1.0.3

1.0.3.0

  Sources   Download

02/03 2015

v1.0.2

1.0.2.0

  Sources   Download

02/03 2015

v1.0.1

1.0.1.0

  Sources   Download