english/libraries/joomla/installer/helper.php
/**
	 * Downloads a package
	 *
	 * @param   string URL of file to download
	 * @param   string Download target filename [optional]
	 *
	 * @return  mixed    Path to downloaded package or boolean false on failure
	 * @since   11.1
	 */
Downloads a package
@param   string URL of file to download
@param   string Download target filename [optional]

@return  mixed    Path to downloaded package or boolean false on failure
@since   11.1
Downloads a package @param string URL of file to download @param string Download target filename [ optional ] @return mixed Path to downloaded package or boolean false on failure @since 11 . 1
public static function downloadPackage($url, $target = false)
	{
		$config = JFactory::getConfig();
		$php_errormsg = 'Error Unknown';
		$track_errors = ini_get('track_errors');
		ini_set('track_errors', true);
		jimport('joomla.version');
		$version = new JVersion();
		ini_set('user_agent', $version->getUserAgent('Installer'));
		$inputHandle = @ fopen($url, "r");
		$error = strstr($php_errormsg,'failed to open stream:');
		if (!$inputHandle) {
			JError::raiseWarning(42, JText::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $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];
			}
		}
		if (!$target) {
			$target = $config->get('tmp_path') . '/' . self::getFilenameFromURL($url);
		}
		else {
			$target = $config->get('tmp_path') . '/' . basename($target);
		}
		$contents = null;
		while (!feof($inputHandle))
		{
			$contents .= fread($inputHandle, 4096);
			if ($contents === false)
			{
				JError::raiseWarning(44, JText::sprintf('JLIB_INSTALLER_ERROR_FAILED_READING_NETWORK_RESOURCES', $php_errormsg));
				return false;
			}
		}
		JFile::write($target, $contents);
		fclose($inputHandle);
		ini_set('track_errors',$track_errors);
		@set_time_limit(ini_get('max_execution_time'));
		return basename($target);
	}
public static function downloadPackage ( $ url , $ target = false ) { $ config = JFactory :: getConfig ( ) ; $ php_errormsg = 'Error Unknown' ; $ track_errors = ini_get ( 'track_errors' ) ; ini_set ( 'track_errors' , true ) ; jimport ( 'joomla.version' ) ; $ version = new JVersion ( ) ; ini_set ( 'user_agent' , $ version -> getUserAgent ( 'Installer' ) ) ; $ inputHandle = @ fopen ( $ url , " r " ) ; $ error = strstr ( $ php_errormsg , 'failed to open stream:' ) ; if ( ! $ inputHandle ) { JError :: raiseWarning ( 42 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT' , $ 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 ] ; } } if ( ! $ target ) { $ target = $ config -> get ( 'tmp_path' ) . '/' . self :: getFilenameFromURL ( $ url ) ; } else { $ target = $ config -> get ( 'tmp_path' ) . '/' . basename ( $ target ) ; } $ contents = null ; while ( ! feof ( $ inputHandle ) ) { $ contents .= fread ( $ inputHandle , 4096 ) ; if ( $ contents === false ) { JError :: raiseWarning ( 44 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_FAILED_READING_NETWORK_RESOURCES' , $ php_errormsg ) ) ; return false ; } } JFile :: write ( $ target , $ contents ) ; fclose ( $ inputHandle ) ; ini_set ( 'track_errors' , $ track_errors ) ; @ set_time_limit ( ini_get ( 'max_execution_time' ) ) ; return basename ( $ target ) ; }
Downloads a package
 @param   string URL of file to download
 @param   string Download target filename [optional]
Downloads a package @param string URL of file to download @param string Download target filename [ optional ]
// Capture PHP errors // Set user agent // Open the remote server socket for reading // Set the target path if not given // Initialise contents buffer // Write buffer to file // Close file pointer resource // Restore error tracking to what it was before // bump the max execution time because not using built in php zip libs are slow // Return the name of the downloaded package