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


PHP http::absoluteURLs方法代码示例

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


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

示例1: render

 /**
  * Renders passed in content to a PDF.
  *
  * If $outputTo == '', then the temporary filename is returned, with the expectation
  * that the caller will correctly handle the streaming of the content.
  *
  * @param string $content
  * 			Raw content to render into a pdf
  * @param string $outputTo
  * 				'file' or 'browser'
  * @param string $outname
  * 				A filename if the pdf is sent direct to the browser
  * @return string
  * 				The filename of the output file
  */
 public function render($content, $outputTo = null, $outname = '')
 {
     $tempFolder = getTempFolder();
     if (!is_dir($tempFolder)) {
         throw new Exception("Could not find TMP directory");
     }
     $pdfFolder = $tempFolder . '/pdfrenditions';
     if (!file_exists($pdfFolder)) {
         @mkdir($pdfFolder);
     }
     if (!is_dir($pdfFolder)) {
         throw new Exception("PDF temp directory could not be found");
     }
     $in = tempnam($pdfFolder, "html_");
     chmod($in, 0664);
     $content = $this->fixLinks($content);
     $content = str_replace(' ', ' ', $content);
     $content = http::absoluteURLs($content);
     file_put_contents($in, $content);
     $mid = tempnam($pdfFolder, "xhtml_");
     chmod($mid, 0664);
     $out = tempnam($pdfFolder, "pdf_") . '.pdf';
     if (class_exists('Tidy')) {
         $this->tidyHtml($in, $mid);
     } else {
         $this->tidyHtmlExternal($in, $mid);
     }
     // then run it through our pdfing thing
     $jarPath = dirname(dirname(dirname(__FILE__))) . '/thirdparty/xhtmlrenderer';
     $classpath = $jarPath . '/flying-saucer-core-9.0.7.jar' . PATH_SEPARATOR . $jarPath . '/flying-saucer-pdf-9.0.7.jar' . PATH_SEPARATOR . $jarPath . '/itext-4.2.1.jar';
     $cmd = self::$java_bin;
     if (!is_executable($cmd)) {
         $cmd = "java";
     }
     $escapefn = 'escapeshellarg';
     $cmd = "{$cmd} -classpath " . $escapefn($classpath) . " org.xhtmlrenderer.simple.PDFRenderer " . $escapefn($mid) . ' ' . $escapefn($out);
     $retVal = exec($cmd, $output, $return);
     if (!file_exists($out)) {
         throw new Exception("Could not generate pdf using command {$cmd}: " . var_export($output, true));
     }
     unlink($in);
     unlink($mid);
     if (!($outputTo == 'browser')) {
         return $out;
     }
     if (file_exists($out)) {
         $size = filesize($out);
         $type = "application/pdf";
         $name = urlencode(htmlentities($outname));
         if (!headers_sent()) {
             // set cache-control headers explicitly for https traffic, otherwise no-cache will be used,
             // which will break file attachments in IE
             // Thanks to Niklas Forsdahl <niklas@creamarketing.com>
             if (isset($_SERVER['HTTPS'])) {
                 header('Cache-Control: private');
                 header('Pragma: ');
             }
             header('Content-disposition: attachment; filename=' . $name);
             header('Content-type: application/pdf');
             //octet-stream');
             header('Content-Length: ' . $size);
             readfile($out);
         } else {
             echo "Invalid file";
         }
     }
     unlink($out);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-pdfrendition,代码行数:83,代码来源:PDFRenditionService.php


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