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

Class: HTTP_Download

Source Location: /HTTP_Download-0.6.2/Download.php

Class Overview

HTTP_Header
   |
   --HTTP_Download

Send HTTP Downloads.


Author(s):

Version:

  • $Revision: 1.22 $

Methods


Inherited Variables

Inherited Methods


Class Details

[line 129]
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!

Usage Example 1:

  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($paramsfalse);

Usage Example 2:

  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();

Usage Example 3:

  1.  $dl &new HTTP_Download();
  2.  $dl->setData($blob_from_db);
  3.  $dl->setLastModified($unix_timestamp);
  4.  $dl->setContentType('application/x-gzip');
  5.  $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT'latest.tgz');
  6.  $dl->send();

  • Author: Michael Wallner <mike@php.net>
  • Version: $Revision: 1.22 $
  • Access: public


[ Top ]


Method Detail

HTTP_Download (Constructor)   [line 223]

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:
  • '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 ]

guessContentType   [line 687]

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 content type couldn't be guessed.

  • Return: true on success or PEAR_Error
  • Throws: PEAR_Error
  • Access: public

[ Top ]

send   [line 451]

mixed send( )

Send file

Error constants Returns PEAR_Error if:

  • HTTP headers were already sent
  • HTTP Range was invalid
  • Download was 'not modified since'

  • Return: Returns true on success, false if cached or <classname>PEAR_Error</clasname> on failure.
  • Throws: PEAR_Error
  • Access: public

[ Top ]

sendArchive   [line 746]

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

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

Parameters:

string   $name   —  name the sent archive should have
mixed   $files   —  files/directories
string   $type   —  archive type
string   $add_path   — 
string   $strip_path   — 

[ Top ]

setContentDisposition   [line 402]

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

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

Set content type of file for download

Error constants Returns PEAR_Error if $content_type doesn't seem to be valid.

  • Return: true on success or PEAR_Error
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $content_type   —  content type of file for download

[ Top ]

setData   [line 303]

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

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

Set path to file for download

Error constants

  • Return: true on success or PEAR_Error
  • Throws: PEAR_Error
  • 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 352]

mixed setGzip( [bool $gzip = false])

Whether to gzip the download

Error constants Returns a PEAR_Error if ext/zlib is not available

  • Return: true on success or PEAR_Error
  • Throws: PEAR_Error
  • Access: public

Parameters:

bool   $gzip   —  whether to gzip the download

[ Top ]

setLastModified   [line 376]

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

mixed setParams( array $params)

Set parameters

Error constants

  • Return: true on success or PEAR_Error
  • See: HTTP_Download::HTTP_Download()
  • Throws: PEAR_Error
  • Access: public

Parameters:

array   $params   —  associative array of parameters

[ Top ]

setResource   [line 321]

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 if $handle is no valid resource.

  • Return: true on success or PEAR_Error
  • Throws: PEAR_Error
  • Access: public

Parameters:

int   $handle   —  resource handle

[ Top ]

staticSend   [line 718]

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

Static send

Error constants

  • Return: true on success or PEAR_Error
  • See: HTTP_Download::HTTP_Download()
  • See: HTTP_Download::send()
  • Throws: PEAR_Error
  • 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 10:15:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.