当前位置: 首页>>代码示例>>PHP>>正文


PHP JInstallerHelper::getFilenameFromURL方法代码示例

本文整理汇总了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);
 }
开发者ID:joebushi,项目名称:joomla,代码行数:58,代码来源:helper.php

示例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');
 }
开发者ID:sural98,项目名称:joomla-cms,代码行数:11,代码来源:JInstallerHelperTest.php

示例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);
 }
开发者ID:apiceweb,项目名称:MageBridgeCore,代码行数:29,代码来源:update.php

示例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);
 }
开发者ID:JeroenJ3,项目名称:pkg_scriptmerge,代码行数:28,代码来源:install.php


注:本文中的JInstallerHelper::getFilenameFromURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。