Esempio n. 1
0
 /**
  * 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 array(host,port,errno,errmsg)
  *  'writefailed' if writing to disk fails, this callback is called
  *                with array(destfile,errmsg)
  *
  * If an HTTP proxy has been configured (http_proxy PEAR_Config
  * setting), the proxy will be used.
  *
  * @param string  $url       the URL to download
  * @param object  $ui        PEAR_Frontend_* instance
  * @param object  $config    PEAR_Config instance
  * @param string  $save_dir  (optional) directory to save file in
  * @param mixed   $callback  (optional) function/method to call for status
  *                           updates
  * @param false|string|array $lastmodified header values to check against
  *                                         for caching
  *                                         use false to return the header
  *                                         values from this download
  * @param false|array        $accept       Accept headers to send
  * @param false|string       $channel      Channel to use for retrieving
  *                                         authentication
  *
  * @return mixed  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().  If caching is requested, then return the header
  *                values.
  *                If $lastmodified was given and the there are no changes,
  *                boolean false is returned.
  *
  * @access public
  */
 function downloadHttp($url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null, $accept = false, $channel = false)
 {
     if (!class_exists('PEAR_Downloader')) {
         require_once 'PEAR/Downloader.php';
     }
     return PEAR_Downloader::_downloadHttp($this, $url, $ui, $save_dir, $callback, $lastmodified, $accept, $channel);
 }