本文整理汇总了PHP中JInstallerHelper::getFilenameFromURL方法的典型用法代码示例。如果您正苦于以下问题:PHP JInstallerHelper::getFilenameFromURL方法的具体用法?PHP JInstallerHelper::getFilenameFromURL怎么用?PHP JInstallerHelper::getFilenameFromURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JInstallerHelper
的用法示例。
在下文中一共展示了JInstallerHelper::getFilenameFromURL方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadPackage
/**
* Downloads a package
*
* @static
* @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 1.5
*/
function downloadPackage($url, $target = false)
{
$config =& JFactory::getConfig();
// Capture PHP errors
$php_errormsg = 'Error Unknown';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Set user agent
jimport('joomla.version');
$version = new JVersion();
ini_set('user_agent', $version->getUserAgent('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);
}
// Initialise 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
fclose($inputHandle);
// restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Return the name of the downloaded package
return basename($target);
}
示例2: testGetFilenameFromURL
/**
* Tests the getFilenameFromURL method
*
* @since 3.1
*
* @return void
*/
public function testGetFilenameFromURL()
{
$this->assertThat(JInstallerHelper::getFilenameFromURL('http://update.joomla.org/core/list.xml'), $this->equalTo('list.xml'), 'JInstallerHelper::getFilenameFromURL should return the last portion of the URL');
}
示例3: downloadPackage
/**
* Download a specific package using the MageBridge Proxy (CURL-based)
*
* @param string $url
* @param string $target
* @return string
*/
public static function downloadPackage($url, $target = false)
{
$app = JFactory::getApplication();
// Open the remote server socket for reading
$proxy = MageBridgeModelProxy::getInstance();
$data = $proxy->getRemote($url, null, 'get', false);
if (empty($data)) {
JError::raiseWarning(42, JText::_('REMOTE_DOWNLOAD_FAILED') . ', ' . $error);
return false;
}
// Set the target path if not given
$config = JFactory::getConfig();
if (!$target) {
$target = $config->get('tmp_path') . '/' . JInstallerHelper::getFilenameFromURL($url);
} else {
$target = $config->get('tmp_path') . '/' . basename($target);
}
// Write received data to file
file_put_contents($target, $data);
// Return the name of the downloaded package
return basename($target);
}
示例4: downloadPackage
public static function downloadPackage($url, $file = null)
{
// System variables
$app = JFactory::getApplication();
// Use fopen() instead
if (ini_get('allow_url_fopen') == 1) {
return JInstallerHelper::downloadPackage($url, $file);
}
// Set the target path if not given
if (empty($file)) {
$file = $app->getCfg('tmp_path') . '/' . JInstallerHelper::getFilenameFromURL($url);
} else {
$file = $app->getCfg('tmp_path') . '/' . basename($file);
}
// Open the remote server socket for reading
$ch = curl_init($url);
curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_MAXREDIRS => 2, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_FRESH_CONNECT => false, CURLOPT_FORBID_REUSE => false, CURLOPT_BUFFERSIZE => 8192));
$data = curl_exec($ch);
curl_close($ch);
if (empty($data)) {
JError::raiseWarning(42, JText::_('LIB_YIREO_HELPER_INSTALL_REMOTE_DOWNLOAD_FAILED') . ', ' . $error);
return false;
}
// Write received data to file
JFile::write($file, $data);
// Return the name of the downloaded package
return basename($file);
}