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


PHP GeneralUtility::tempnam方法代码示例

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


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

示例1: getContent

 /**
  * get Content of PDF file
  * @param string $file
  * @return string The extracted content of the file
  */
 public function getContent($file)
 {
     $this->fileInfo = GeneralUtility::makeInstance('tx_kesearch_lib_fileinfo');
     $this->fileInfo->setFile($file);
     // get PDF informations
     if (!($pdfInfo = $this->getPdfInfo($file))) {
         return false;
     }
     // proceed only of there are any pages found
     if ((int) $pdfInfo['pages'] && $this->isAppArraySet) {
         // create the tempfile which will contain the content
         $tempFileName = GeneralUtility::tempnam('pdf_files-Indexer');
         // Delete if exists, just to be safe.
         @unlink($tempFileName);
         // generate and execute the pdftotext commandline tool
         $fileEscaped = CommandUtility::escapeShellArgument($file);
         $cmd = "{$this->app['pdftotext']} -enc UTF-8 -q {$fileEscaped} {$tempFileName}";
         CommandUtility::exec($cmd);
         // check if the tempFile was successfully created
         if (@is_file($tempFileName)) {
             $content = GeneralUtility::getUrl($tempFileName);
             unlink($tempFileName);
         } else {
             $this->addError('Content for file ' . $file . ' could not be extracted. Maybe it is encrypted?');
             // return empty string if no content was found
             $content = '';
         }
         return $this->removeEndJunk($content);
     } else {
         return false;
     }
 }
开发者ID:teaminmedias-pluswerk,项目名称:ke_search,代码行数:37,代码来源:class.tx_kesearch_indexer_filetypes_pdf.php

示例2: process

 /**
  * This method actually does the processing of files locally
  *
  * takes the original file (on remote storages this will be fetched from the remote server)
  * does the IM magic on the local server by creating a temporary typo3temp/ file
  * copies the typo3temp/ file to the processing folder of the target storage
  * removes the typo3temp/ file
  *
  * @param TaskInterface $task
  * @return array
  */
 public function process(TaskInterface $task)
 {
     $targetFile = $task->getTargetFile();
     // Merge custom configuration with default configuration
     $configuration = array_merge(array('width' => 64, 'height' => 64), $task->getConfiguration());
     $configuration['width'] = Utility\MathUtility::forceIntegerInRange($configuration['width'], 1, 1000);
     $configuration['height'] = Utility\MathUtility::forceIntegerInRange($configuration['height'], 1, 1000);
     $originalFileName = $targetFile->getOriginalFile()->getForLocalProcessing(FALSE);
     // Create a temporary file in typo3temp/
     if ($targetFile->getOriginalFile()->getExtension() === 'jpg') {
         $targetFileExtension = '.jpg';
     } else {
         $targetFileExtension = '.png';
     }
     // Create the thumb filename in typo3temp/preview_....jpg
     $temporaryFileName = Utility\GeneralUtility::tempnam('preview_') . $targetFileExtension;
     // Check file extension
     if ($targetFile->getOriginalFile()->getType() != Resource\File::FILETYPE_IMAGE && !Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $targetFile->getOriginalFile()->getExtension())) {
         // Create a default image
         $this->processor->getTemporaryImageWithText($temporaryFileName, 'Not imagefile!', 'No ext!', $targetFile->getOriginalFile()->getName());
     } else {
         // Create the temporary file
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . $this->processor->wrapFileName($originalFileName) . '[0] ' . $this->processor->wrapFileName($temporaryFileName);
             $cmd = Utility\GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
             Utility\CommandUtility::exec($cmd);
             if (!file_exists($temporaryFileName)) {
                 // Create a error gif
                 $this->processor->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', $targetFile->getOriginalFile()->getName());
             }
         }
     }
     return array('filePath' => $temporaryFileName);
 }
开发者ID:nicksergio,项目名称:TYPO3v4-Core,代码行数:45,代码来源:LocalPreviewHelper.php

示例3: createPublicTempFile

 public static function createPublicTempFile($prefix, $suffix)
 {
     $fullname = GeneralUtility::tempnam($prefix, $suffix);
     $urlname = preg_replace('/.*(?=\\/typo3temp)/', '', $fullname);
     $url = GeneralUtility::locationHeaderUrl($urlname);
     return ['name' => $fullname, 'url' => $url];
 }
开发者ID:ksjogo,项目名称:typo3-ext-semantic-images,代码行数:7,代码来源:Utility.php

示例4: download

 /**
  * @param string $fileref
  */
 public function download($fileref)
 {
     $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sharepoint_connector']);
     $extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::removeDotsFromTS($extensionConfiguration);
     $filePath = explode(';#', $fileref);
     $urlInfo = parse_url($extensionConfiguration['sharepointServer']['url']);
     $downloadLink = $urlInfo['scheme'] . '://' . $urlInfo['host'] . '/' . $filePath[1];
     $destinationFile = \TYPO3\CMS\Core\Utility\GeneralUtility::tempnam('spdownload_');
     $fp = fopen($destinationFile, 'w+');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $downloadLink);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
     curl_setopt($ch, CURLOPT_USERPWD, $extensionConfiguration['sharepointServer']['username'] . ':' . $extensionConfiguration['sharepointServer']['password']);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     # increase timeout to download big file
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_exec($ch);
     curl_close($ch);
     fclose($fp);
     if (file_exists($destinationFile)) {
         header("Content-Type: application/force-download");
         header("Content-Disposition: attachment; filename=" . basename($downloadLink));
         header("Content-Transfer-Encoding: binary");
         header('Content-Length: ' . filesize($destinationFile));
         ob_clean();
         flush();
         readfile($destinationFile);
     }
     \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($destinationFile);
 }
开发者ID:kj187,项目名称:sharepoint_connector,代码行数:35,代码来源:Attachment.php

示例5: setUp

 /**
  * Set up
  *
  * @return void
  */
 protected function setUp()
 {
     $this->subject = new \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider();
     $this->icon = GeneralUtility::makeInstance(Icon::class);
     $this->icon->setIdentifier('foo');
     $this->icon->setSize(Icon::SIZE_SMALL);
     $svgTestFileContent = '<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#CD201F" d="M11 12l3-2v6H2v-6l3 2 3-2 3 2z"></path><script><![CDATA[ function alertMe() {} ]]></script></svg>';
     $this->testFileName = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
     file_put_contents($this->testFileName, $svgTestFileContent);
 }
开发者ID:rickymathew,项目名称:TYPO3.CMS,代码行数:15,代码来源:SvgIconProviderTest.php

示例6: createFakeExtension

 /**
  * Creates a fake extension with a given table definition.
  *
  * @param string $tableDefinition SQL script to create the extension's tables
  * @throws \RuntimeException
  * @return void
  */
 protected function createFakeExtension($tableDefinition)
 {
     // Prepare a fake extension configuration
     $ext_tables = GeneralUtility::tempnam('ext_tables');
     if (!GeneralUtility::writeFile($ext_tables, $tableDefinition)) {
         throw new \RuntimeException('Can\'t write temporary ext_tables file.');
     }
     $this->temporaryFiles[] = $ext_tables;
     $GLOBALS['TYPO3_LOADED_EXT'] = array('test_dbal' => array('ext_tables.sql' => $ext_tables));
     // Append our test table to the list of existing tables
     $this->subject->initialize();
 }
开发者ID:KarlDennisMatthaei1923,项目名称:PierraaDesign,代码行数:19,代码来源:DatabaseConnectionTest.php

示例7: isCaseSensitiveFilesystem

 /**
  * Test if the local filesystem is case sensitive
  *
  * @return boolean
  */
 protected function isCaseSensitiveFilesystem()
 {
     $caseSensitive = TRUE;
     $path = GeneralUtility::tempnam('aAbB');
     // do the actual sensitivity check
     if (@file_exists(strtoupper($path)) && @file_exists(strtolower($path))) {
         $caseSensitive = FALSE;
     }
     // clean filesystem
     unlink($path);
     return $caseSensitive;
 }
开发者ID:samuweiss,项目名称:TYPO3-Site,代码行数:17,代码来源:AbstractImportTestCase.php

示例8: process

 /**
  * @param TaskInterface $task
  * @return array|null
  */
 protected function process(TaskInterface $task)
 {
     $result = NULL;
     $sourceFile = $task->getOriginalProcessedFile() ?: $task->getSourceFile();
     $sourceFilePath = realpath($sourceFile->getForLocalProcessing(FALSE));
     $targetFilePath = realpath(GeneralUtility::tempnam('_processed_/nlx-tempfile-', '.' . $sourceFile->getExtension()));
     switch ($sourceFile->getExtension()) {
         case 'jpg':
         case 'jpeg':
             if ($this->settings['jpg.']['enabled'] === FALSE) {
                 return $result;
             }
             $library = 'jpegtran';
             $arguments = sprintf('-copy none -optimize %s -outfile %s %s', $this->settings['jpg.']['progressive'] === TRUE ? '-progressive' : '', escapeshellarg($targetFilePath), escapeshellarg($sourceFilePath));
             break;
         case 'png':
             if ($this->settings['png.']['enabled'] === FALSE) {
                 return $result;
             }
             $library = 'optipng';
             $arguments = sprintf('-o%u -strip all -fix -clobber -force -out %s %s', $this->settings['png.']['optimizationLevel'], escapeshellarg($targetFilePath), escapeshellarg($sourceFilePath));
             break;
         case 'gif':
             if ($this->settings['gif.']['enabled'] === FALSE) {
                 return $result;
             }
             $library = 'gifsicle';
             $arguments = sprintf('--batch -O%u -o %s %s', $this->settings['gif.']['optimizationLevel'], escapeshellarg($targetFilePath), escapeshellarg($sourceFilePath));
             break;
         case 'svg':
             if ($this->settings['svg.']['enabled'] === FALSE) {
                 return $result;
             }
             $library = 'svgo';
             $arguments = sprintf('%s %s', escapeshellarg($sourceFilePath), escapeshellarg($targetFilePath));
             break;
         default:
             return $result;
     }
     $cmd = escapeshellcmd($library) . ' ' . $arguments;
     $output = [];
     exec($cmd, $output, $return);
     if ($return === 0) {
         $result = array('filePath' => $targetFilePath);
     }
     return $result;
 }
开发者ID:netlogix,项目名称:nximageoptimizer,代码行数:51,代码来源:OptimizeImageProcessor.php

示例9: getContent

 /**
  * get Content of DOC file
  * @param string $file
  * @return string The extracted content of the file
  */
 public function getContent($file)
 {
     // create the tempfile which will contain the content
     $tempFileName = GeneralUtility::tempnam('xls_files-Indexer');
     // Delete if exists, just to be safe.
     @unlink($tempFileName);
     // generate and execute the pdftotext commandline tool
     $fileEscaped = CommandUtility::escapeShellArgument($file);
     $cmd = "{$this->app['xls2csv']} -c ' ' -q 0 -s8859-1 -dutf-8 {$fileEscaped} > {$tempFileName}";
     CommandUtility::exec($cmd);
     // check if the tempFile was successfully created
     if (@is_file($tempFileName)) {
         $content = GeneralUtility::getUrl($tempFileName);
         unlink($tempFileName);
     } else {
         return false;
     }
     // check if content was found
     if (strlen($content)) {
         return $content;
     } else {
         return false;
     }
 }
开发者ID:teaminmedias-pluswerk,项目名称:ke_search,代码行数:29,代码来源:class.tx_kesearch_indexer_filetypes_xls.php

示例10: tempFile

 /**
  * Create a temporary file.
  *
  * @param string $filePrefix File prefix.
  * @return string|boolean File name or FALSE
  * @todo Define visibility
  */
 public function tempFile($filePrefix)
 {
     $absFile = \TYPO3\CMS\Core\Utility\GeneralUtility::tempnam($filePrefix);
     if ($absFile) {
         $ret = $absFile;
         $this->registerTempFile($absFile);
     } else {
         $ret = FALSE;
         $this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not create temp file.');
     }
     return $ret;
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:19,代码来源:AbstractService.php

示例11: spellCheckHandler

 /**
  * Handler for the content of a tag
  */
 public function spellCheckHandler($xml_parser, $string)
 {
     $incurrent = array();
     $stringText = $string;
     $words = preg_split($this->parserCharset == 'utf-8' ? '/\\P{L}+/u' : '/\\W+/', $stringText);
     foreach ($words as $word) {
         $word = preg_replace('/ /' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '', $word);
         if ($word && !is_numeric($word)) {
             if ($this->pspell_is_available && !$this->forceCommandMode) {
                 if (!pspell_check($this->pspell_link, $word)) {
                     if (!in_array($word, $this->misspelled)) {
                         if (sizeof($this->misspelled) != 0) {
                             $this->suggestedWords .= ',';
                         }
                         $suggest = array();
                         $suggest = pspell_suggest($this->pspell_link, $word);
                         if (sizeof($suggest) != 0) {
                             $this->suggestionCount++;
                             $this->suggestedWordCount += sizeof($suggest);
                         }
                         $this->suggestedWords .= '"' . $word . '":"' . implode(',', $suggest) . '"';
                         $this->misspelled[] = $word;
                         unset($suggest);
                     }
                     if (!in_array($word, $incurrent)) {
                         $stringText = preg_replace('/\\b' . $word . '\\b/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '<span class="htmlarea-spellcheck-error">' . $word . '</span>', $stringText);
                         $incurrent[] = $word;
                     }
                 }
             } else {
                 $tmpFileName = GeneralUtility::tempnam($this->filePrefix);
                 if (!($filehandle = fopen($tmpFileName, 'wb'))) {
                     echo 'SpellChecker tempfile open error';
                 }
                 if (!fwrite($filehandle, $word)) {
                     echo 'SpellChecker tempfile write error';
                 }
                 if (!fclose($filehandle)) {
                     echo 'SpellChecker tempfile close error';
                 }
                 $catCommand = TYPO3_OS === 'WIN' ? 'type' : 'cat';
                 $AspellCommand = $catCommand . ' ' . escapeshellarg($tmpFileName) . ' | ' . $this->AspellDirectory . ' -a check' . ' --mode=none' . ' --sug-mode=' . escapeshellarg($this->pspellMode) . ($this->personalDictionaryPath ? ' --home-dir=' . escapeshellarg($this->personalDictionaryPath) : '') . ' --lang=' . escapeshellarg($this->dictionary) . ' --encoding=' . escapeshellarg($this->aspellEncoding) . ' 2>&1';
                 $AspellAnswer = shell_exec($AspellCommand);
                 $AspellResultLines = array();
                 $AspellResultLines = GeneralUtility::trimExplode(LF, $AspellAnswer, TRUE);
                 if (substr($AspellResultLines[0], 0, 6) == 'Error:') {
                     echo '{' . $AspellAnswer . '}';
                 }
                 GeneralUtility::unlink_tempfile($tmpFileName);
                 if ($AspellResultLines['1'][0] !== '*') {
                     if (!in_array($word, $this->misspelled)) {
                         if (sizeof($this->misspelled) != 0) {
                             $this->suggestedWords .= ',';
                         }
                         $suggest = array();
                         $suggestions = array();
                         if ($AspellResultLines['1'][0] === '&') {
                             $suggestions = GeneralUtility::trimExplode(':', $AspellResultLines['1'], TRUE);
                             $suggest = GeneralUtility::trimExplode(',', $suggestions['1'], TRUE);
                         }
                         if (sizeof($suggest) != 0) {
                             $this->suggestionCount++;
                             $this->suggestedWordCount += sizeof($suggest);
                         }
                         $this->suggestedWords .= '"' . $word . '":"' . implode(',', $suggest) . '"';
                         $this->misspelled[] = $word;
                         unset($suggest);
                         unset($suggestions);
                     }
                     if (!in_array($word, $incurrent)) {
                         $stringText = preg_replace('/\\b' . $word . '\\b/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '<span class="htmlarea-spellcheck-error">' . $word . '</span>', $stringText);
                         $incurrent[] = $word;
                     }
                 }
                 unset($AspellResultLines);
             }
             $this->wordCount++;
         }
     }
     $this->text .= $stringText;
     unset($incurrent);
 }
开发者ID:adrolli,项目名称:TYPO3.CMS,代码行数:85,代码来源:SpellCheckingController.php

示例12: templateWithErrorReturnsFormWithErrorReporter

 /**
  * @test
  */
 public function templateWithErrorReturnsFormWithErrorReporter()
 {
     $badSource = '<f:layout invalid="TRUE" />';
     $temp = GeneralUtility::tempnam('badtemplate') . '.html';
     GeneralUtility::writeFileToTypo3tempDir($temp, $badSource);
     $form = $this->createFluxServiceInstance()->getFormFromTemplateFile($temp);
     $this->assertInstanceOf('FluidTYPO3\\Flux\\Form', $form);
     $this->assertInstanceOf('FluidTYPO3\\Flux\\Form\\Field\\UserFunction', reset($form->getFields()));
     $this->assertEquals('FluidTYPO3\\Flux\\UserFunction\\ErrorReporter->renderField', reset($form->getFields())->getFunction());
 }
开发者ID:samuweiss,项目名称:TYPO3-Site,代码行数:13,代码来源:FluxServiceTest.php

示例13: tempnamReturnsAbsolutePathInsideDocumentRoot

 /**
  * @test
  */
 public function tempnamReturnsAbsolutePathInsideDocumentRoot()
 {
     $filePath = GeneralUtility::tempnam('foo');
     $this->assertStringStartsWith(PATH_site, $filePath);
 }
开发者ID:hlop,项目名称:TYPO3.CMS,代码行数:8,代码来源:GeneralUtilityTest.php

示例14: getTemporaryPathForFile

 /**
  * Returns a temporary path for a given file, including the file extension.
  *
  * @param \TYPO3\CMS\Core\Resource\FileInterface $file
  * @return string
  */
 protected function getTemporaryPathForFile(\TYPO3\CMS\Core\Resource\FileInterface $file)
 {
     return \TYPO3\CMS\Core\Utility\GeneralUtility::tempnam('fal-tempfile-') . '.' . $file->getExtension();
 }
开发者ID:nicksergio,项目名称:TYPO3v4-Core,代码行数:10,代码来源:AbstractDriver.php

示例15: processMedia

 /**
  * @param array $data
  * @param ImportSource $importSource
  * @return NULL|array
  */
 protected function processMedia(array $data, ImportSource $importSource)
 {
     $media = NULL;
     if (empty($data['image']) && $importSource->getDefaultImage()) {
         return array(array('type' => 0, 'image' => $importSource->getDefaultImage()->getOriginalResource()->getCombinedIdentifier(), 'showinpreview' => 1));
     }
     $folder = NULL;
     if ($importSource->getImageFolder()) {
         try {
             $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier(ltrim($importSource->getImageFolder(), 'file:'));
         } catch (\Exception $e) {
         }
     }
     if (!empty($data['image']) && $folder) {
         $media = array();
         if (!is_array($data['image'])) {
             $data['image'] = array($data['image']);
         }
         foreach ($data['image'] as $image) {
             $tmp = GeneralUtility::getUrl($image);
             if ($tmp) {
                 $tempFile = GeneralUtility::tempnam('news_importer');
                 file_put_contents($tempFile, $tmp);
                 list(, , $imageType) = getimagesize($tempFile);
                 try {
                     $falImage = $folder->addFile($tempFile, ($data['title'] ?: 'news_import') . image_type_to_extension($imageType, TRUE), 'changeName');
                     $media[] = array('type' => 0, 'image' => $falImage->getCombinedIdentifier(), 'showinpreview' => 1);
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     return $media;
 }
开发者ID:ruudsilvrants,项目名称:news_importer,代码行数:39,代码来源:ImportService.php


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