本文整理汇总了PHP中TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile方法的典型用法代码示例。如果您正苦于以下问题:PHP GeneralUtility::unlink_tempfile方法的具体用法?PHP GeneralUtility::unlink_tempfile怎么用?PHP GeneralUtility::unlink_tempfile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\GeneralUtility
的用法示例。
在下文中一共展示了GeneralUtility::unlink_tempfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
* Tear down test case
*/
public function tearDown()
{
foreach ($this->testFilesToDelete as $absoluteFileName) {
\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
}
parent::tearDown();
}
示例2: 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);
}
示例3: tearDown
public function tearDown()
{
\TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
foreach ($this->globals as $key => $value) {
$GLOBALS[$key] = unserialize($value);
}
foreach ($this->testFilesToDelete as $absoluteFileName) {
\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
}
\TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
}
示例4: tearDown
public function tearDown()
{
ExtensionManagementUtility::clearExtensionKeyMap();
foreach ($this->testFilesToDelete as $absoluteFileName) {
\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
}
if (file_exists(PATH_site . 'typo3temp/test_ext/')) {
\TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3temp/test_ext/', TRUE);
}
ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager);
ExtensionManagementUtilityAccessibleProxy::setCacheManager(NULL);
$GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->backUpPackageManager);
\TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
parent::tearDown();
}
示例5: init
//.........这里部分代码省略.........
}
// If incoming data is seen...
if (is_array($this->dataArr) && count(ArrayUtility::removeArrayEntryByValue(array_keys($this->dataArr), 'captcha'))) {
// Evaluation of data:
$this->parseValues();
$this->overrideValues();
$this->evalValues();
if ($this->conf['evalFunc']) {
$this->dataArr = $this->userProcess('evalFunc', $this->dataArr);
}
/*
debug($this->dataArr);
debug($this->failure);
debug($this->preview);
*/
// if not preview and no failures, then set data...
if (!$this->failure && !$this->preview && !GeneralUtility::_GP('doNotSave')) {
// doNotSave is a global var (eg a 'Cancel' submit button) that prevents the data from being processed
$this->save();
} else {
if ($this->conf['debug']) {
debug($this->failure);
}
}
} else {
$this->defaultValues();
// If no incoming data, this will set the default values.
$this->preview = 0;
// No preview if data is not received
}
if ($this->failure) {
$this->preview = 0;
}
// No preview flag if a evaluation failure has occured
$this->previewLabel = $this->preview ? '_PREVIEW' : '';
// Setting preview label prefix.
// *********************
// DISPLAY FORMS:
// ***********************
if ($this->saved) {
// Clear page cache
$this->clearCacheIfSet();
$this->setNoCacheHeader();
// Displaying the page here that says, the record has been saved. You're able to include the saved values by markers.
switch ($this->cmd) {
case 'delete':
$key = 'DELETE';
break;
case 'edit':
$key = 'EDIT';
break;
default:
$key = 'CREATE';
break;
}
// Output message
$templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_' . $key . '_SAVED###');
$this->setCObjects($templateCode, $this->currentArr);
$markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', true, 'FIELD_', $this->recInMarkersHSC);
$content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
// email message:
$this->compileMail($key . '_SAVED', [$this->currentArr], $this->currentArr[$this->conf['email.']['field']], $this->conf['setfixed.']);
} elseif ($this->error) {
// If there was an error, we return the template-subpart with the error message
$templateCode = $this->cObj->getSubpart($this->templateCode, $this->error);
$this->setCObjects($templateCode);
$content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray);
} else {
// Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form:
if (!$this->cmd) {
$this->cmd = $this->conf['defaultCmd'];
}
if ($this->conf['debug']) {
debug('Display form: ' . $this->cmd, 1);
}
switch ($this->cmd) {
case 'setfixed':
$content = $this->procesSetFixed();
break;
case 'infomail':
$content = $this->sendInfoMail();
break;
case 'delete':
$content = $this->displayDeleteScreen();
break;
case 'edit':
$content = $this->displayEditScreen();
break;
case 'create':
$content = $this->displayCreateScreen();
break;
}
}
// Delete temp files:
foreach ($this->unlinkTempFiles as $tempFileName) {
GeneralUtility::unlink_tempfile($tempFileName);
}
// Return content:
return $content;
}
示例6: __destruct
/**
* Do some cleanup at the end (deleting attachment files)
*/
public function __destruct()
{
foreach ($this->temporaryFiles as $file) {
if (\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($file) && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($file, PATH_site . 'typo3temp/upload_temp_')) {
\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($file);
}
}
}
示例7: 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);
}
示例8: process
//.........这里部分代码省略.........
}
$options = $this->getConfigurationForImageCropScaleMask($targetFile, $gifBuilder);
$croppedImage = null;
if (!empty($configuration['crop'])) {
// check if it is a json object
$cropData = json_decode($configuration['crop']);
if ($cropData) {
$crop = implode(',', array((int) $cropData->x, (int) $cropData->y, (int) $cropData->width, (int) $cropData->height));
} else {
$crop = $configuration['crop'];
}
list($offsetLeft, $offsetTop, $newWidth, $newHeight) = explode(',', $crop, 4);
$backupPrefix = $gifBuilder->filenamePrefix;
$gifBuilder->filenamePrefix = 'crop_';
// the result info is an array with 0=width,1=height,2=extension,3=filename
$result = $gifBuilder->imageMagickConvert($originalFileName, '', '', '', sprintf('-crop %dx%d+%d+%d', $newWidth, $newHeight, $offsetLeft, $offsetTop), '', ['noScale' => true], true);
$gifBuilder->filenamePrefix = $backupPrefix;
if ($result !== null) {
$originalFileName = $croppedImage = $result[3];
}
}
// Normal situation (no masking)
if (!(is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'])) {
// SVG
if ($croppedImage === null && $sourceFile->getExtension() === 'svg') {
$newDimensions = $this->getNewSvgDimensions($sourceFile, $configuration, $options, $gifBuilder);
$result = array(0 => $newDimensions['width'], 1 => $newDimensions['height'], 3 => '');
// all other images
} else {
// the result info is an array with 0=width,1=height,2=extension,3=filename
$result = $gifBuilder->imageMagickConvert($originalFileName, $configuration['fileExtension'], $configuration['width'], $configuration['height'], $configuration['additionalParameters'], $configuration['frame'], $options);
}
} else {
$targetFileName = $this->getFilenameForImageCropScaleMask($task);
$temporaryFileName = $gifBuilder->tempPath . $targetFileName;
$maskImage = $configuration['maskImages']['maskImage'];
$maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
if ($maskImage instanceof Resource\FileInterface && $maskBackgroundImage instanceof Resource\FileInterface) {
$temporaryExtension = 'png';
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif']) {
// If ImageMagick version 5+
$temporaryExtension = $gifBuilder->gifExtension;
}
$tempFileInfo = $gifBuilder->imageMagickConvert($originalFileName, $temporaryExtension, $configuration['width'], $configuration['height'], $configuration['additionalParameters'], $configuration['frame'], $options);
if (is_array($tempFileInfo)) {
$maskBottomImage = $configuration['maskImages']['maskBottomImage'];
if ($maskBottomImage instanceof Resource\FileInterface) {
$maskBottomImageMask = $configuration['maskImages']['maskBottomImageMask'];
} else {
$maskBottomImageMask = null;
}
// Scaling: ****
$tempScale = array();
$command = '-geometry ' . $tempFileInfo[0] . 'x' . $tempFileInfo[1] . '!';
$command = $this->modifyImageMagickStripProfileParameters($command, $configuration);
$tmpStr = $gifBuilder->randomName();
// m_mask
$tempScale['m_mask'] = $tmpStr . '_mask.' . $temporaryExtension;
$gifBuilder->imageMagickExec($maskImage->getForLocalProcessing(true), $tempScale['m_mask'], $command);
// m_bgImg
$tempScale['m_bgImg'] = $tmpStr . '_bgImg.miff';
$gifBuilder->imageMagickExec($maskBackgroundImage->getForLocalProcessing(), $tempScale['m_bgImg'], $command);
// m_bottomImg / m_bottomImg_mask
if ($maskBottomImage instanceof Resource\FileInterface && $maskBottomImageMask instanceof Resource\FileInterface) {
$tempScale['m_bottomImg'] = $tmpStr . '_bottomImg.' . $temporaryExtension;
$gifBuilder->imageMagickExec($maskBottomImage->getForLocalProcessing(), $tempScale['m_bottomImg'], $command);
$tempScale['m_bottomImg_mask'] = $tmpStr . '_bottomImg_mask.' . $temporaryExtension;
$gifBuilder->imageMagickExec($maskBottomImageMask->getForLocalProcessing(), $tempScale['m_bottomImg_mask'], $command);
// BEGIN combining:
// The image onto the background
$gifBuilder->combineExec($tempScale['m_bgImg'], $tempScale['m_bottomImg'], $tempScale['m_bottomImg_mask'], $tempScale['m_bgImg']);
}
// The image onto the background
$gifBuilder->combineExec($tempScale['m_bgImg'], $tempFileInfo[3], $tempScale['m_mask'], $temporaryFileName);
$tempFileInfo[3] = $temporaryFileName;
// Unlink the temp-images...
foreach ($tempScale as $tempFile) {
if (@is_file($tempFile)) {
unlink($tempFile);
}
}
}
$result = $tempFileInfo;
}
}
// check if the processing really generated a new file (scaled and/or cropped)
if ($result !== null) {
if ($result[3] !== $originalFileName || $originalFileName === $croppedImage) {
$result = array('width' => $result[0], 'height' => $result[1], 'filePath' => $result[3]);
} else {
// No file was generated
$result = null;
}
}
// Cleanup temp file if it isn't used as result
if ($croppedImage && ($result === null || $croppedImage !== $result['filePath'])) {
GeneralUtility::unlink_tempfile($croppedImage);
}
return $result;
}
示例9: unlink_tempfileReturnsNullIfFileIsNowWithinTypo3temp
/**
* @test
*/
public function unlink_tempfileReturnsNullIfFileIsNowWithinTypo3temp()
{
$returnValue = GeneralUtility::unlink_tempfile('/tmp/typo3-unit-test-unlink_tempfile');
$this->assertNull($returnValue);
}
示例10: filelinkCreatesCorrectUrlForFileWithUrlEncodedSpecialChars
/**
* @test
*/
public function filelinkCreatesCorrectUrlForFileWithUrlEncodedSpecialChars()
{
$fileNameAndPath = PATH_site . 'typo3temp/var/tests/phpunitJumpUrlTestFile with spaces & amps.txt';
file_put_contents($fileNameAndPath, 'Some test data');
$relativeFileNameAndPath = substr($fileNameAndPath, strlen(PATH_site));
$fileName = substr($fileNameAndPath, strlen(PATH_site . 'typo3temp/var/tests/'));
$expectedLink = str_replace('%2F', '/', rawurlencode($relativeFileNameAndPath));
$result = $this->subject->filelink($fileName, array('path' => 'typo3temp/var/tests/'));
$this->assertEquals('<a href="' . $expectedLink . '">' . $fileName . '</a>', $result);
\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileNameAndPath);
}
示例11: processFile
/**
* Process file
* Create static image preview for Online Media item when possible
*
* @param FileProcessingService $fileProcessingService
* @param AbstractDriver $driver
* @param ProcessedFile $processedFile
* @param File $file
* @param string $taskType
* @param array $configuration
*/
public function processFile(FileProcessingService $fileProcessingService, AbstractDriver $driver, ProcessedFile $processedFile, File $file, $taskType, array $configuration)
{
if ($taskType !== 'Image.Preview' && $taskType !== 'Image.CropScaleMask') {
return;
}
// Check if processing is needed
if (!$this->needsReprocessing($processedFile)) {
return;
}
// Check if there is a OnlineMediaHelper registered for this file type
$helper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($file);
if ($helper === false) {
return;
}
// Check if helper provides a preview image
$temporaryFileName = $helper->getPreviewImage($file);
if (empty($temporaryFileName) || !file_exists($temporaryFileName)) {
return;
}
$temporaryFileNameForResizedThumb = uniqid(PATH_site . 'typo3temp/var/transient/online_media_' . $file->getHashedIdentifier()) . '.jpg';
switch ($taskType) {
case 'Image.Preview':
// Merge custom configuration with default configuration
$configuration = array_merge(array('width' => 64, 'height' => 64), $configuration);
$configuration['width'] = MathUtility::forceIntegerInRange($configuration['width'], 1, 1000);
$configuration['height'] = MathUtility::forceIntegerInRange($configuration['height'], 1, 1000);
$this->resizeImage($temporaryFileName, $temporaryFileNameForResizedThumb, $configuration);
break;
case 'Image.CropScaleMask':
$this->cropScaleImage($temporaryFileName, $temporaryFileNameForResizedThumb, $configuration);
break;
}
GeneralUtility::unlink_tempfile($temporaryFileName);
if (is_file($temporaryFileNameForResizedThumb)) {
$processedFile->setName($this->getTargetFileName($processedFile));
list($width, $height) = getimagesize($temporaryFileNameForResizedThumb);
$processedFile->updateProperties(array('width' => $width, 'height' => $height, 'size' => filesize($temporaryFileNameForResizedThumb), 'checksum' => $processedFile->getTask()->getConfigurationChecksum()));
$processedFile->updateWithLocalFile($temporaryFileNameForResizedThumb);
GeneralUtility::unlink_tempfile($temporaryFileNameForResizedThumb);
/** @var ProcessedFileRepository $processedFileRepository */
$processedFileRepository = GeneralUtility::makeInstance(ProcessedFileRepository::class);
$processedFileRepository->add($processedFile);
}
}
示例12: handleUpload
protected function handleUpload($property, $uploadDir, $filename, &$path, $maxSize = '2097152', $filetypes = "jpg,png")
{
$data = $_FILES['tx_' . strtolower($this->request->getControllerExtensionName()) . '_' . strtolower($this->request->getPluginName())];
if (is_array($data) && count($data) > 0) {
$propertyPath = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', $property);
$namePath = $data['name'];
$tmpPath = $data['tmp_name'];
$sizePath = $data['size'];
foreach ($propertyPath as $segment) {
$namePath = $namePath[$segment];
$tmpPath = $tmpPath[$segment];
$sizePath = $sizePath[$segment];
}
if ($namePath !== NULL && $namePath !== '') {
$fileArray = array('name' => $namePath, 'tmp' => $tmpPath, 'size' => $sizePath);
} else {
return 1;
}
} else {
return 0;
}
if ($fileArray['size'] > $maxSize) {
return 2;
}
$fileInfo = pathinfo($fileArray['name']);
if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($filetypes, strtolower($fileInfo['extension']))) {
return 3;
}
if (file_exists(PATH_site . $uploadDir . $filename)) {
$filename = $filename . '-' . time() . '.' . $fileInfo['extension'];
}
if (\TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($fileArray['tmp'], PATH_site . $uploadDir . $filename . '.' . $fileInfo['extension'])) {
$path = $filename . '.' . $fileInfo['extension'];
return 0;
} else {
\TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($fileArray['tmp']);
return 4;
}
}
示例13: removeFiles
/**
* Remove uploaded files from the typo3temp
*
* @return void
*/
protected function removeFiles()
{
$sessionData = $this->getSessionData();
if (is_array($sessionData)) {
foreach ($sessionData as $fieldName => $values) {
if (is_array($values)) {
foreach ($values as $file) {
if (isset($file['tempFilename'])) {
GeneralUtility::unlink_tempfile($file['tempFilename']);
}
}
}
}
}
}
示例14: removePublicTempFile
public static function removePublicTempFile($temp)
{
GeneralUtility::unlink_tempfile($temp['name']);
}
示例15: createNewFile
/**
* Create new OnlineMedia item container file.
* This is created inside typo3temp/ and then moved from FAL to the proper storage.
*
* @param Folder $targetFolder
* @param string $fileName
* @param string $onlineMediaId
* @return File
*/
protected function createNewFile(Folder $targetFolder, $fileName, $onlineMediaId)
{
$temporaryFile = GeneralUtility::tempnam('online_media');
GeneralUtility::writeFileToTypo3tempDir($temporaryFile, $onlineMediaId);
$file = $targetFolder->addFile($temporaryFile, $fileName, DuplicationBehavior::RENAME);
GeneralUtility::unlink_tempfile($temporaryFile);
return $file;
}