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


PHP tao_helpers_File::getPathFromUrl方法代码示例

本文整理汇总了PHP中tao_helpers_File::getPathFromUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP tao_helpers_File::getPathFromUrl方法的具体用法?PHP tao_helpers_File::getPathFromUrl怎么用?PHP tao_helpers_File::getPathFromUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tao_helpers_File的用法示例。


在下文中一共展示了tao_helpers_File::getPathFromUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: retrieveFile

 /**
  * Retrieve a file from a given $url and copy it to its final $destination.
  * 
  * @param string $url The URL to be dereferenced.
  * @param string $destination The destination of the retrieved file, on the file system.
  * @return boolean|string false If an error occurs during the retrieval/copy process, or the final destination name if it succeeds.
  */
 public static function retrieveFile($url, $destination)
 {
     $fileName = basename($url);
     //check file name compatibility:
     //e.g. if a file with a common name (e.g. car.jpg, house.png, sound.mp3) already exists in the destination folder
     while (file_exists($destination . $fileName)) {
         $lastDot = strrpos($fileName, '.');
         $fileName = substr($fileName, 0, $lastDot) . '_' . substr($fileName, $lastDot);
     }
     // Since the file has not been downloaded yet, start downloading it using cUrl
     // Only if the resource is external, else we copy it
     if (!preg_match('@^' . ROOT_URL . '@', $url)) {
         common_Logger::d('Downloading ' . $url);
         helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::NO_TIMEOUT);
         $fp = fopen($destination . $fileName, 'w+');
         $curlHandler = curl_init();
         curl_setopt($curlHandler, CURLOPT_URL, $url);
         curl_setopt($curlHandler, CURLOPT_FILE, $fp);
         curl_setopt($curlHandler, CURLOPT_TIMEOUT, 50);
         curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, true);
         //if there is an http auth on the local domain, it's mandatory to auth with curl
         if (USE_HTTP_AUTH) {
             $addAuth = false;
             $domains = array('localhost', '127.0.0.1', ROOT_URL);
             foreach ($domains as $domain) {
                 if (preg_match("/" . preg_quote($domain, '/') . "/", $url)) {
                     $addAuth = true;
                 }
             }
             if ($addAuth) {
                 curl_setopt($curlHandler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                 curl_setopt($curlHandler, CURLOPT_USERPWD, USE_HTTP_USER . ":" . USE_HTTP_PASS);
             }
         }
         curl_exec($curlHandler);
         $httpCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
         $success = $httpCode == 200;
         curl_close($curlHandler);
         fclose($fp);
         helpers_TimeOutHelper::reset();
     } else {
         $path = tao_helpers_File::getPathFromUrl($url);
         common_Logger::d('Copying ' . $path);
         $success = helpers_File::copy($path, $destination . $fileName);
     }
     if ($success == false) {
         common_Logger::w('Unable to retrieve ' . $url);
         return false;
     } else {
         return $destination . $fileName;
     }
 }
开发者ID:nagyist,项目名称:tao-extension-tao-item,代码行数:59,代码来源:class.Deployment.php


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