PEAR_Common::downloadHttp

PEAR_Common::downloadHttp() – Download a file through HTTP

Synopsis

require_once 'PEAR/common.php';

string PEAR_Common::downloadHttp ( string $url , object &$ui , string $save_dir = '.' , mixed $callback = null )

Description

Download a file through HTTP. Considers suggested file name in Content-disposition: header and can run a callback function for different events. The callback will be called with two parameters: the callback type, and parameters. The implemented callback types are:

  • 'setup' - called at the very beginning, parameter is a UI object that should be used for all output

  • 'message' - the parameter is a string with an informational message

  • 'saveas' - may be used to save with a different file name, the parameter is the filename that is about to be used. If a 'saveas' callback returns a non-empty string, that file name will be used as the filename instead. Note that $save_dir will not be affected by this, only the basename of the file.

  • 'start' - download is starting, parameter is number of bytes that are expected, or -1 if unknown

  • 'bytesread' - parameter is the number of bytes read so far

  • 'done' - download is complete, parameter is the total number of bytes read

  • 'connfailed' - if the TCP connection fails, this callback is called with

    <?php
    array(host,port,errno,errmsg)
    ?>
  • 'writefailed' - if writing to disk fails, this callback is called with

    <?php
    array(destfile,errmsg)
    ?>

If an HTTP proxy has been configured (http_proxy PEAR_Config setting), the proxy will be used.

Parameter

string $url

the URL to download

object &$ui

PEAR_Frontend_* instance

string $save_dir

directory to save file in

mixed $callback

function/method to call for status updates

object $config

PEAR_Config instance

Return value

string - Returns the full path of the downloaded file or a PEAR error on failure. If the error is caused by socket-related errors, the error object will have the fsockopen error code available through getCode().

Throws

Possible PEAR_Error values
Error code Error value Meaning Solution
  "    

Note

This function can not be called statically.

Build a array (Previous) Returns package information from different sources (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.