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

Class: HTTP_Download

Source Location: /HTTP_Download-0.8.1/Download.php

Class Overview


Send HTTP Downloads.


Author(s):

Version:

  • $Revision: 1.32 $

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 98]
Send HTTP Downloads.

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: 1.32 $
  • Access: public


[ Top ]


Class Variables

$cache =  true

[line 142]

Whether to allow caching of the download on the clients side

Error constants

  • Access: protected

Type:   bool


[ Top ]

$data =  null

[line 117]

Data for download

Error constants

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

Type:   string


[ Top ]

$etag =  ''

[line 188]

ETag

Error constants

  • Access: protected

Type:   string


[ Top ]

$file =  ''

[line 108]

Path to file for download

Error constants

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

Type:   string


[ Top ]

$gzip =  false

[line 134]

Whether to gzip the download

Error constants

  • Access: protected

Type:   bool


[ Top ]

$handle =  null

[line 126]

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',
        'Accept-Ranges' => 'bytes',
        'Connection'    => 'close'
    )

[line 166]

HTTP headers

Error constants

  • Access: protected

Type:   array


[ Top ]

$HTTP =  null

[line 180]

HTTP_Header

Error constants

  • Access: protected

Type:   object


[ Top ]

$lastModified =  ''

[line 158]

Last modified (GMT)

Error constants

  • Access: protected

Type:   string


[ Top ]

$size =  0

[line 150]

Size of download

Error constants

  • Access: protected

Type:   int


[ Top ]



Method Detail

HTTP_Download (Constructor)   [line 221]

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

one of:

  • 'file' => path to file for download
  • 'data' => raw data for download
  • 'resource' => resource handle for download
    and any of:
  • 'cache' => whether to allow cs caching
  • 'gzip' => whether to gzip the download
  • 'lastmodified' => unix timestamp
  • 'contenttype' => content type of download
  • 'contentdisposition' => content disposition

'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 856]

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 ]

generateETag   [line 682]

string generateETag( )

Generate ETag

Error constants

  • Access: protected

[ Top ]

getChunks   [line 770]

array getChunks( )

Get chunks to send

Error constants

  • Access: protected

[ Top ]

getRanges   [line 807]

array getRanges( )

Get range request

Error constants

  • Access: protected

[ Top ]

guessContentType   [line 487]

mixed guessContentType( )

Guess content type of file

Error constants This only works if PHP is installed with ext/magic.mime AND php.ini is setup correct! Otherwise it will result in a FATAL ERROR. So be WARNED!

Returns PEAR_Error if:

  • 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_DONWLOAD_E_INVALID_CONTENT_TYPE)

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

[ Top ]

isCached   [line 819]

bool isCached( )

Check if entity is cached

Error constants

  • Access: protected

[ Top ]

isRangeRequest   [line 793]

bool isRangeRequest( )

Check if range is requested

Error constants

  • Access: protected

[ Top ]

isValidRange   [line 835]

bool isValidRange( )

Check if entity hasn't changed

Error constants

  • Access: protected

[ Top ]

send   [line 520]

mixed send( )

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

[ Top ]

sendArchive   [line 627]

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_BZ2,
  6.       '',
  7.       '/var/ftp/pub'
  8.   );

  • Return: Returns true on success or PEAR_Error on failure.
  • See: Archive_Tar::createModify()
  • 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 730]

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 701]

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 872]

void sendHeaders( )

Send HTTP headers

Error constants

  • Access: protected

[ Top ]

setCache   [line 390]

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 ]

setContentDisposition   [line 433]

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 458]

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 317]

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 ]

setFile   [line 290]

mixed setFile( string $file, [bool $send_404 = 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 status if $send_404 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_404   —  whether to send HTTP/404 if the file wasn't found

[ Top ]

setGzip   [line 365]

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 407]

void setLastModified( int $last_modified)

Set "Last-Modified"

Error constants This is usually determined by filemtime($file) 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 249]

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 334]

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 ]

staticSend   [line 586]

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 ]


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