Intro
Вернуться к: HTTP_Download
Intro
HTTP_Download provides an interface to easily send any arbitrary data to HTTP clients. HTTP_Download can gain its data from variables, files or stream resources.
With this package you can easily handle (hidden) downloads. Hidden means not accessible by the public - for instance if you want to restrict access to particular downloads.
It supports HTTP compression, caching and partial downloads, resuming and sending raw data, for example from database BLOBs.
ATTENTION: You shouldn't use this package together with ob_gzhandler or zlib.output_compression enabled in your php.ini, especially if you want to send already gzipped data!
Usage Examples:
Have a look at the following examples:
Static send:
<?php
1 $params = array(
2 'file' => '../hidden/download.tgz',
3 'contenttype' => 'application/x-gzip',
4 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'latest.tgz'),
5 );
6
7 $error = HTTP_Download::staticSend($params, false);
?>
Send a hidden file:
<?php
1 $dl = &new HTTP_Download();
2 $dl->setFile('../hidden/download.tgz');
3 $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, 'latest.tgz');
4 // with ext/magic.mime
5 // $dl->guessContentType();
6 // else:
7 $dl->setContentType('application/x-gzip');
8 $dl->send();
?>
Send arbitrary data:
<?php
1 $dl = &new HTTP_Download();
2 $dl->setData($data);
3 $dl->setLastModified($unix_timestamp);
4 $dl->setContentType('application/x-gzip');
5 $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, 'latest.tgz');
6 $dl->send();
?>
Limiting bandwidth:
<?php
1 $dl = &new HTTP_Download();
2 $dl->setFile('huge_file.bin');
3 $dl->setBufferSize(25 * 1024); // 25 K
4 $dl->setThrottleDelay(1); // 1 sec
5 $dl->send();
?>
Sending a PostgreSQL LOB:
<?php
1 require_once 'HTTP/Download.php';
2 require_once 'HTTP/Download/PgLOB.php';
3 $dl = &new HTTP_Download();
4 $dl->setResource(
5 HTTP_Download_PgLOB::open(pg_connect('dbname=lobs'), 12345));
6 $dl->send();
?>
Вернуться к: HTTP_Download