apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: HTTP_Download

Source Location: /HTTP_Download-1.1.4/HTTP/Download.php

Class Overview


Send HTTP Downloads/Responses.


Author(s):

Version:

  • $Revision: 304423 $

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 91]
Send HTTP Downloads/Responses.

Error constants

With this package you can handle (hidden) downloads. It supports partial downloads, resuming and sending raw data ie. 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!

  • Version: $Revision: 304423 $
  • Access: public


[ Top ]


Class Variables

$bufferSize =  2097152

[line 189]

Buffer Size

Error constants

  • Access: protected

Type:   int


[ Top ]

$cache =  true

[line 135]

Whether to allow caching of the download on the clients side

Error constants

  • Access: protected

Type:   bool


[ Top ]

$data =  null

[line 110]

Data for download

Error constants

  • See: HTTP_Download::setData()
  • Access: protected

Type:   string


[ Top ]

$etag =  ''

[line 181]

ETag

Error constants

  • Access: protected

Type:   string


[ Top ]

$file =  ''

[line 101]

Path to file for download

Error constants

  • See: HTTP_Download::setFile()
  • Access: protected

Type:   string


[ Top ]

$gzip =  false

[line 127]

Whether to gzip the download

Error constants

  • Access: protected

Type:   bool


[ Top ]

$handle =  null

[line 119]

Resource handle for download

Error constants

  • See: HTTP_Download::setResource()
  • Access: protected

Type:   int


[ Top ]

$headers = array(
        'Content-Type'  => 'application/x-octetstream',
        'Pragma'        => 'cache',
        'Cache-Control' => 'public, must-revalidate, max-age=0',
        'Accept-Ranges' => 'bytes',
        'X-Sent-By'     => 'PEAR::HTTP::Download'
    )

[line 159]

HTTP headers

Error constants

  • Access: protected

Type:   array


[ Top ]

$HTTP =  null

[line 173]

HTTP_Header

Error constants

  • Access: protected

Type:   object


[ Top ]

$lastModified =  0

[line 151]

Last modified

Error constants

  • Access: protected

Type:   int


[ Top ]

$sentBytes =  0

[line 205]

Sent Bytes

Error constants

  • Access: public

Type:   int


[ Top ]

$size =  0

[line 143]

Size of download

Error constants

  • Access: protected

Type:   int


[ Top ]

$throttleDelay =  0

[line 197]

Throttle Delay

Error constants

  • Access: protected

Type:   float


[ Top ]

$_error =  null

[line 213]

Startup error

Error constants

  • Access: protected

Type:   PEAR_Error


[ Top ]



Method Detail

HTTP_Download (Constructor)   [line 250]

HTTP_Download HTTP_Download( [array $params = array()])

Constructor

Error constants Set supplied parameters.

  • See: HTTP_Download::setContentDisposition()
  • Access: public

Parameters:

array   $params   — 

associative array of parameters <strong>one of:</strong>

  • 'file' => path to file for download
  • 'data' => raw data for download
  • 'resource' => resource handle for download
<strong>and any of:</strong>
  • 'cache' => whether to allow cs caching
  • 'gzip' => whether to gzip the download
  • 'lastmodified' => unix timestamp
  • 'contenttype' => content type of download
  • 'contentdisposition' => content disposition
  • 'buffersize' => amount of bytes to buffer
  • 'throttledelay' => amount of secs to sleep
  • 'cachecontrol' => cache privacy and validity

'Content-Disposition' is not HTTP compliant, but most browsers follow this header, so it was borrowed from MIME standard.

It looks like this: "Content-Disposition: attachment; filename=example.tgz".


[ Top ]

compareAsterisk   [line 1163]

bool compareAsterisk( string $svar, string $compare)

Compare against an asterisk or check for equality

Error constants

  • Access: protected

Parameters:

string   $svar   —  key for the $_SERVER array
string   $compare   —  string to compare

[ Top ]

flush   [line 1201]

void flush( [string $data = ''])

Flush

Error constants

  • Access: protected

Parameters:

string   $data   — 

[ Top ]

generateETag   [line 825]

string generateETag( )

Generate ETag

Error constants

  • Access: protected

[ Top ]

getChunks   [line 936]

array getChunks( )

Get chunks to send

Error constants


[ Top ]

getRanges   [line 1100]

array getRanges( )

Get range request

Error constants

  • Access: protected

[ Top ]

guessContentType   [line 628]

mixed guessContentType( )

Guess content type of file

Error constants First we try to use PEAR::MIME_Type, if installed, to detect the content type, else we check if ext/mime_magic is loaded and properly configured.

Returns PEAR_Error if:

  • if PEAR::MIME_Type failed to detect a proper content type (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)
  • ext/magic.mime is not installed, or not properly configured (HTTP_DOWNLOAD_E_NO_EXT_MMAGIC)
  • mime_content_type() couldn't guess content type or returned a content type considered to be bogus by setContentType() (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE)

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

[ Top ]

isCached   [line 1112]

bool isCached( )

Check if entity is cached

Error constants

  • Access: protected

[ Top ]

isRangeRequest   [line 1086]

bool isRangeRequest( )

Check if range is requested

Error constants

  • Access: protected

[ Top ]

isValidRange   [line 1129]

bool isValidRange( )

Check if entity hasn't changed

Error constants

  • Access: protected

[ Top ]

mergeChunks   [line 1048]

array mergeChunks( array $chunks)

Merges consecutive chunks to avoid overlaps

Error constants

  • Return: merged ranges
  • Author: Philippe Jausions <jausions@php.net>
  • Access: protected

Parameters:

array   $chunks   —  Ranges to merge

[ Top ]

send   [line 674]

mixed send( [bool $autoSetContentDisposition = true])

Send

Error constants Returns PEAR_Error if:

  • HTTP headers were already sent (HTTP_DOWNLOAD_E_HEADERS_SENT)
  • HTTP Range was invalid (HTTP_DOWNLOAD_E_INVALID_REQUEST)

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

Parameters:

bool   $autoSetContentDisposition   —  Whether to set the Content-Disposition header if it isn't already.

[ Top ]

sendArchive   [line 806]

mixed sendArchive( string $name, mixed $files, [string $type = HTTP_DOWNLOAD_TGZ], [string $add_path = ''], [string $strip_path = ''])

Send a bunch of files or directories as an archive

Error constants Example:

  1.   require_once 'HTTP/Download.php';
  2.   HTTP_Download::sendArchive(
  3.       'myArchive.tgz',
  4.       '/var/ftp/pub/mike',
  5.       HTTP_DOWNLOAD_TGZ,
  6.       '',
  7.       '/var/ftp/pub'
  8.   );

  • Return: Returns true on success or PEAR_Error on failure.
  • See: Archive_Tar::createModify()
  • Deprecated: use HTTP_Download_Archive::send()
  • Access: public

Parameters:

string   $name   —  name the sent archive should have
mixed   $files   —  files/directories
string   $type   —  archive type
string   $add_path   —  path that should be prepended to the files
string   $strip_path   —  path that should be stripped from the files

[ Top ]

sendChunk   [line 877]

mixed sendChunk( array $chunk, [string $cType = null], [string $bound = null])

Send chunk of data

Error constants

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: protected

Parameters:

array   $chunk   —  start and end offset of the chunk to send
string   $cType   —  actual content type
string   $bound   —  boundary for multipart/byteranges

[ Top ]

sendChunks   [line 850]

mixed sendChunks( array $chunks)

Send multiple chunks

Error constants

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: protected

Parameters:

array   $chunks   — 

[ Top ]

sendHeaders   [line 1179]

void sendHeaders( )

Send HTTP headers

Error constants

  • Access: protected

[ Top ]

setBufferSize   [line 490]

mixed setBufferSize( [int $bytes = 2097152])

Set Size of Buffer

Error constants The amount of bytes specified as buffer size is the maximum amount of data read at once from resources or files. The default size is 2M (2097152 bytes). Be aware that if you enable gzip compression and you set a very low buffer size that the actual file size may grow due to added gzip headers for each sent chunk of the specified size.

Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_PARAM) if $size is not greater than 0 bytes.

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

Parameters:

int   $bytes   —  Amount of bytes to use as buffer.

[ Top ]

setCache   [line 429]

void setCache( [bool $cache = true])

Whether to allow caching

Error constants If set to true (default) we'll send some headers that are commonly used for caching purposes like ETag, Cache-Control and Last-Modified.

If caching is disabled, we'll send the download no matter if it would actually be cached at the client side.

  • Access: public

Parameters:

bool   $cache   —  whether to allow caching

[ Top ]

setCacheControl   [line 445]

bool setCacheControl( [string $cache = 'public'], [int $maxage = 0])

Whether to allow proxies to cache

Error constants If set to 'private' proxies shouldn't cache the response. This setting defaults to 'public' and affects only cached responses.

  • Access: public

Parameters:

string   $cache   —  private or public
int   $maxage   —  maximum age of the client cache entry

[ Top ]

setContentDisposition   [line 571]

void setContentDisposition( [string $disposition = HTTP_DOWNLOAD_ATTACHMENT], [string $file_name = null])

Set Content-Disposition header

Error constants

  • See: HTTP_Download::HTTP_Download
  • Access: public

Parameters:

string   $disposition   —  whether to send the download inline or as attachment
string   $file_name   — 

the filename to display in the browser's download window

Example:

  1.  $HTTP_Download->setContentDisposition(
  2.    HTTP_DOWNLOAD_ATTACHMENT,
  3.    'download.tgz'
  4.  );


[ Top ]

setContentType   [line 594]

mixed setContentType( [string $content_type = 'application/x-octetstream'])

Set content type of the download

Error constants Default content type of the download will be 'application/x-octetstream'. Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) if $content_type doesn't seem to be valid.

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

Parameters:

string   $content_type   —  content type of file for download

[ Top ]

setData   [line 347]

void setData( [$data $data = null])

Set data for download

Error constants Set $data to null if you want to unset this.

  • Access: public

Parameters:

$data   $data   —  raw data to send

[ Top ]

setETag   [line 469]

void setETag( [string $etag = null])

Set ETag

Error constants Sets a user-defined ETag for cache-validation. The ETag is usually generated by HTTP_Download through its payload information.

  • Access: public

Parameters:

string   $etag   —  Entity tag used for strong cache validation.

[ Top ]

setFile   [line 307]

mixed setFile( string $file, [bool $send_error = true])

Set path to file for download

Error constants The Last-Modified header will be set to files filemtime(), actually. Returns PEAR_Error (HTTP_DOWNLOAD_E_INVALID_FILE) if file doesn't exist. Sends HTTP 404 or 403 status if $send_error is set to true.

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

Parameters:

string   $file   —  path to file for download
bool   $send_error   —  whether to send HTTP/404 or 403 if the file wasn't found or is not readable

[ Top ]

setGzip   [line 400]

mixed setGzip( [bool $gzip = false])

Whether to gzip the download

Error constants Returns a PEAR_Error (HTTP_DOWNLOAD_E_NO_EXT_ZLIB) if ext/zlib is not available/loadable.

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

Parameters:

bool   $gzip   —  whether to gzip the download

[ Top ]

setLastModified   [line 546]

void setLastModified( int $last_modified)

Set "Last-Modified"

Error constants This is usually determined by filemtime() in HTTP_Download::setFile() If you set raw data for download with HTTP_Download::setData() and you want do send an appropiate "Last-Modified" header, you should call this method.

  • Access: public

Parameters:

int   $last_modified   —  unix timestamp

[ Top ]

setParams   [line 269]

mixed setParams( array $params)

Set parameters

Error constants Set supplied parameters through its accessor methods.

  • Return: Returns true on success or PEAR_Error on failure.
  • See: HTTP_Download::HTTP_Download()
  • Access: public

Parameters:

array   $params   —  associative array of parameters

[ Top ]

setResource   [line 364]

mixed setResource( [int $handle = null])

Set resource for download

Error constants The resource handle supplied will be closed after sending the download. Returns a PEAR_Error (HTTP_DOWNLOAD_E_INVALID_RESOURCE) if $handle is no valid resource. Set $handle to null if you want to unset this.

  • Return: Returns true on success or PEAR_Error on failure.
  • Access: public

Parameters:

int   $handle   —  resource handle

[ Top ]

setThrottleDelay   [line 529]

void setThrottleDelay( [float $seconds = 0])

Set Throttle Delay

Error constants Set the amount of seconds to sleep after each chunck that has been sent. One can implement some sort of throttle through adjusting the buffer size and the throttle delay. With the following settings HTTP_Download will sleep a second after each 25 K of data sent.

  1.   Array(
  2.       'throttledelay' => 1,
  3.       'buffersize'    => 1024 * 25,
  4.   )

Just be aware that if gzipp'ing is enabled, decreasing the chunk size too much leads to proportionally increased network traffic due to added gzip header and bottom bytes around each chunk.

  • Access: public

Parameters:

float   $seconds   —  Amount of seconds to sleep after each chunk that has been sent.

[ Top ]

sleep   [line 1217]

void sleep( )

Sleep

Error constants

  • Access: protected

[ Top ]

sortChunks   [line 1022]

void sortChunks( array &$chunks)

Sorts the ranges to be in ascending order

Error constants


Parameters:

array   &$chunks   —  ranges to sort

[ Top ]

staticSend   [line 764]

mixed staticSend( array $params, [bool $guess = false])

Static send

Error constants

  • Return: Returns true on success or PEAR_Error on failure.
  • See: HTTP_Download::HTTP_Download()
  • See: HTTP_Download::send()
  • Access: public

Parameters:

array   $params   —  associative array of parameters
bool   $guess   —  whether HTTP_Download::guessContentType() should be called

[ Top ]

_getError   [line 1232]

NULL|PEAR_Error _getError( )

Returns and clears startup error

Error constants

  • Return: startup error if one exists
  • Access: protected

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:40:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.