< API15:JInstallerHelper
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.


Downloads a package

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >


downloadPackage($url, $target=false)
Parameter Name Default Value Description
$url URL of file to download
$target false Download target filename [optional]


mixed Path to downloaded package or boolean false on failure

Defined in



jimport( 'joomla.installer.helper' );

Source Body

function downloadPackage($url, $target = false)
        $config =& JFactory::getConfig();
        // Capture PHP errors
        $php_errormsg = 'Error Unknown';
        ini_set('track_errors', true);
        // Set user agent
        ini_set('user_agent', "Joomla! 1.5 Installer");
        // Open the remote server socket for reading
        $inputHandle = @ fopen($url, "r");
        $error = strstr($php_errormsg,'failed to open stream:');
        if (!$inputHandle) {
                JError::raiseWarning(42, JText::_('SERVER_CONNECT_FAILED').', '.$error);
                return false;
        $meta_data = stream_get_meta_data($inputHandle);
        foreach ($meta_data['wrapper_data'] as $wrapper_data)
                if (substr($wrapper_data, 0, strlen("Content-Disposition")) == "Content-Disposition") {
                        $contentfilename = explode ("\"", $wrapper_data);
                        $target = $contentfilename[1];
        // Set the target path if not given
        if (!$target) {
                $target = $config->getValue('config.tmp_path').DS.JInstallerHelper::getFilenameFromURL($url);
        } else {
                $target = $config->getValue('config.tmp_path').DS.basename($target);
        // Initialize contents buffer
        $contents = null;
        while (!feof($inputHandle))
                $contents .= fread($inputHandle, 4096);
                if ($contents == false) {
                        JError::raiseWarning(44, 'Failed reading network resource: '.$php_errormsg);
                        return false;
        // Write buffer to file
        JFile::write($target, $contents);
        // Close file pointer resource
        // Return the name of the downloaded package
        return basename($target);

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >


<CodeExamplesForm />