本文整理汇总了PHP中PhpOffice\PhpWord\Settings::getTempDir方法的典型用法代码示例。如果您正苦于以下问题:PHP Settings::getTempDir方法的具体用法?PHP Settings::getTempDir怎么用?PHP Settings::getTempDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\Settings
的用法示例。
在下文中一共展示了Settings::getTempDir方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
*
* @param string $documentTemplate The fully qualified template filename.
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
* @throws \PhpOffice\PhpWord\Exception\CopyFileException
*/
public function __construct($documentTemplate)
{
// Temporary document filename initialization
$this->temporaryDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
if (false === $this->temporaryDocumentFilename) {
throw new CreateTemporaryFileException();
}
// Template file cloning
if (false === copy($documentTemplate, $this->temporaryDocumentFilename)) {
throw new CopyFileException($documentTemplate, $this->temporaryDocumentFilename);
}
// Temporary document content extraction
$this->zipClass = new ZipArchive();
$this->zipClass->open($this->temporaryDocumentFilename);
$index = 1;
while ($this->zipClass->locateName($this->getHeaderName($index)) !== false) {
$this->temporaryDocumentHeaders[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
$index++;
}
$index = 1;
while ($this->zipClass->locateName($this->getFooterName($index)) !== false) {
$this->temporaryDocumentFooters[$index] = $this->zipClass->getFromName($this->getFooterName($index));
$index++;
}
$this->temporaryDocumentMainPart = $this->zipClass->getFromName('word/document.xml');
}
示例2: __construct
/**
* @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
*
* @param string $documentTemplate The fully qualified template filename.
*
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
* @throws \PhpOffice\PhpWord\Exception\CopyFileException
*/
public function __construct($documentTemplate)
{
// Temporary document filename initialization
$this->tempDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
if (false === $this->tempDocumentFilename) {
throw new CreateTemporaryFileException();
}
// Template file cloning
if (false === copy($documentTemplate, $this->tempDocumentFilename)) {
throw new CopyFileException($documentTemplate, $this->tempDocumentFilename);
}
// Temporary document content extraction
$this->zipClass = new ZipArchive();
$this->zipClass->open($this->tempDocumentFilename);
$index = 1;
while (false !== $this->zipClass->locateName($this->getHeaderName($index))) {
$this->tempDocumentHeaders[$index] = $this->fixBrokenMacros($this->zipClass->getFromName($this->getHeaderName($index)));
$index++;
}
$index = 1;
while (false !== $this->zipClass->locateName($this->getFooterName($index))) {
$this->tempDocumentFooters[$index] = $this->fixBrokenMacros($this->zipClass->getFromName($this->getFooterName($index)));
$index++;
}
$this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName('word/document.xml'));
$this->temporaryWordRelDocumentPart = $this->zipClass->getFromName('word/_rels/document.xml.rels');
$this->temporaryContentType = $this->zipClass->getFromName('[Content_Types].xml');
// clean the temporary document
$this->cleanTemporaryDocument();
}
示例3: testTempDirCanBeSet
/**
* @covers ::setTempDir
* @covers ::getTempDir
* @depends testPhpTempDirIsUsedByDefault
* @test
*/
public function testTempDirCanBeSet()
{
$userDefinedTempDir = 'C:\\PhpWordTemp';
Settings::setTempDir($userDefinedTempDir);
$currentTempDir = Settings::getTempDir();
$this->assertEquals($userDefinedTempDir, $currentTempDir);
$this->assertNotEquals(sys_get_temp_dir(), $currentTempDir);
}
示例4: clear
/**
* Clear document
*/
public static function clear()
{
if (file_exists(self::$file)) {
unlink(self::$file);
}
if (is_dir(Settings::getTempDir() . '/PhpWord_Unit_Test/')) {
self::deleteDir(Settings::getTempDir() . '/PhpWord_Unit_Test/');
}
}
示例5: testSetGetAbstractRendererProperties
/**
* Test set/get abstract renderer properties
*/
public function testSetGetAbstractRendererProperties()
{
define('DOMPDF_ENABLE_AUTOLOAD', false);
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$writer = new PDF(new PhpWord());
$writer->setFont('arial');
$this->assertEquals('arial', $writer->getFont());
$writer->setPaperSize();
$this->assertEquals(9, $writer->getPaperSize());
$writer->setOrientation();
$this->assertEquals('default', $writer->getOrientation());
$writer->setTempDir(Settings::getTempDir());
$this->assertEquals(Settings::getTempDir(), $writer->getTempDir());
}
示例6: __construct
/**
* @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
*
* @param string $documentTemplate The fully qualified template filename.
*
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
* @throws \PhpOffice\PhpWord\Exception\CopyFileException
*/
public function __construct($documentTemplate)
{
// Temporary document filename initialization
$this->tempDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
if (false === $this->tempDocumentFilename) {
throw new CreateTemporaryFileException();
}
// Template file cloning
if (false === copy($documentTemplate, $this->tempDocumentFilename)) {
throw new CopyFileException($documentTemplate, $this->tempDocumentFilename);
}
// Temporary document content extraction
$this->zipClass = new ZipArchive();
$this->zipClass->open($this->tempDocumentFilename);
// Edited by Luan Nguyen
if (! file_exists(BACKEND_V2_TRASH_PATH)) {
mkdir(BACKEND_V2_TRASH_PATH, 0777);
}
$this->zipClass->extractTo(BACKEND_V2_TRASH_PATH);
$index = 1;
while (false !== $this->zipClass->locateName($this->getHeaderName($index))) {
$this->tempDocumentHeaders[$index] = $this->fixBrokenMacros(
$this->zipClass->getFromName($this->getHeaderName($index))
);
$index++;
}
$index = 1;
while (false !== $this->zipClass->locateName($this->getFooterName($index))) {
$this->tempDocumentFooters[$index] = $this->fixBrokenMacros(
$this->zipClass->getFromName($this->getFooterName($index))
);
$index++;
}
$this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName('word/document.xml'));
$this->temporaryDocumentRels = $this->zipClass->getFromName('word/_rels/document.xml.rels');
}
示例7: getTempFile
/**
* Get temporary file name
*
* If $filename is php://output or php://stdout, make it a temporary file
*
* @param string $filename
* @return string
*/
protected function getTempFile($filename)
{
// Temporary directory
$this->setTempDir(Settings::getTempDir() . '/PHPWordWriter/');
// Temporary file
$this->originalFilename = $filename;
if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
$filename = tempnam(Settings::getTempDir(), 'PhpWord');
if (false === $filename) {
$filename = $this->originalFilename;
}
}
$this->tempFilename = $filename;
return $this->tempFilename;
}
示例8: getArchiveImageSize
/**
* Get image size from archive
*
* @since 0.12.0 Throws CreateTemporaryFileException.
*
* @param string $source
* @return array|null
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
*/
private function getArchiveImageSize($source)
{
$imageData = null;
$source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source);
$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
if (false === $tempFilename) {
throw new CreateTemporaryFileException();
}
$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename)) {
$imageContent = $zip->getFromName($imageFilename);
if ($imageContent !== false) {
file_put_contents($tempFilename, $imageContent);
$imageData = getimagesize($tempFilename);
unlink($tempFilename);
}
}
$zip->close();
}
return $imageData;
}
示例9: array
<?php
include_once 'Sample_Header.php';
use PhpOffice\PhpWord\Settings;
$requirements = array('php' => array('PHP 5.3.3', version_compare(PHP_VERSION, '5.3.3', '>=')), 'xml' => array('PHP extension XML', extension_loaded('xml')), 'temp' => array('Temp folder "<code>' . Settings::getTempDir() . '</code>" is writable', is_writable(Settings::getTempDir())), 'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')), 'gd' => array('PHP extension GD (optional)', extension_loaded('gd')), 'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')), 'xsl' => array('PHP extension XSL (optional)', extension_loaded('xsl')));
if (!CLI) {
?>
<div class="jumbotron">
<p>Welcome to PHPWord, a library written in pure PHP that provides a set of classes to write to and read from different document file formats, i.e. Office Open XML (.docx), Open Document Format (.odt), and Rich Text Format (.rtf).</p>
<p> </p>
<p>
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button"><i class="fa fa-github fa-lg" title="GitHub"></i> Fork us on Github!</a>
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a>
</p>
</div>
<?php
}
if (!CLI) {
echo "<h3>Requirement check:</h3>";
echo "<ul>";
foreach ($requirements as $key => $value) {
list($label, $result) = $value;
$status = $result ? 'passed' : 'failed';
echo "<li>{$label} ... <span class='{$status}'>{$status}</span></li>";
}
echo "</ul>";
include_once 'Sample_Footer.php';
} else {
echo 'Requirement check:' . PHP_EOL;
foreach ($requirements as $key => $value) {
list($label, $result) = $value;
示例10: open
/**
* Open a new zip archive
*
* @param string $filename The file name of the ZIP archive to open
* @param int $flags The mode to use to open the archive
* @return bool
*/
public function open($filename, $flags = null)
{
$result = true;
$this->filename = $filename;
if (!$this->usePclzip) {
$zip = new \ZipArchive();
$result = $zip->open($this->filename, $flags);
// Scrutizer will report the property numFiles does not exist
// See https://github.com/scrutinizer-ci/php-analyzer/issues/190
$this->numFiles = $zip->numFiles;
} else {
$zip = new \PclZip($this->filename);
$this->tempDir = Settings::getTempDir();
$this->numFiles = count($zip->listContent());
}
$this->zip = $zip;
return $result;
}