本文整理汇总了PHP中FileUtil::getTemporaryFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::getTemporaryFilename方法的具体用法?PHP FileUtil::getTemporaryFilename怎么用?PHP FileUtil::getTemporaryFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::getTemporaryFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getXML
/**
* Loads the xml file into a string and returns this string.
*
* @return XML $xml
*/
protected function getXML()
{
$instructions = $this->installation->getInstructions();
if (!isset($instructions[$this->tagName]['cdata'])) {
return false;
}
// Search the acpmenu xml-file in the package archive.
// Abort installation in case no file was found.
if (($fileIndex = $this->installation->getArchive()->getTar()->getIndexByFilename($instructions[$this->tagName]['cdata'])) === false) {
throw new SystemException("xml file '" . $instructions[$this->tagName]['cdata'] . "' not found in '" . $this->installation->getArchive()->getArchive() . "'", 13008);
}
// Extract acpmenu file and parse with SimpleXML
$xml = new XML();
$tmpFile = FileUtil::getTemporaryFilename('xml_');
try {
$this->installation->getArchive()->getTar()->extract($fileIndex, $tmpFile);
$xml->loadFile($tmpFile);
} catch (Exception $e) {
// bugfix to avoid file caching problems
try {
$this->installation->getArchive()->getTar()->extract($fileIndex, $tmpFile);
$xml->loadFile($tmpFile);
} catch (Exception $e) {
$this->installation->getArchive()->getTar()->extract($fileIndex, $tmpFile);
$xml->loadFile($tmpFile);
}
}
@unlink($tmpFile);
return $xml;
}
示例2: validateUploadPackage
/**
* Validates the upload package input.
*/
protected function validateUploadPackage()
{
if (empty($this->uploadPackage['tmp_name'])) {
throw new UserInputException('uploadPackage', 'uploadFailed');
}
// get filename
$this->uploadPackage['name'] = FileUtil::getTemporaryFilename('package_', preg_replace('!^.*(?=\\.(?:tar\\.gz|tgz|tar)$)!i', '', basename($this->uploadPackage['name'])));
if (!@move_uploaded_file($this->uploadPackage['tmp_name'], $this->uploadPackage['name'])) {
throw new UserInputException('uploadPackage', 'uploadFailed');
}
$this->archive = new PackageArchive($this->uploadPackage['name'], $this->package);
$this->validateArchive('uploadPackage');
}
示例3: createTargetDir
/**
* @see Installer::createTargetDir()
*/
protected function createTargetDir()
{
if (!FTPUtil::pathExists($this->ftp, $this->ftpPath)) {
if (!FTPUtil::makePath($this->ftp, $this->ftpPath, IS_APACHE_MODULE ? 0777 : 0755)) {
throw new SystemException("cannot create directory '" . $this->ftpPath . "' at ftp server.", 14005);
}
} else {
if (IS_APACHE_MODULE || !is_writeable($this->targetDir)) {
$this->makeWriteable($this->ftpPath);
}
}
// create dummy upload file
$this->dummyUploadFile = FileUtil::getTemporaryFilename('ftpDummy_', '.dat');
@touch($this->dummyUploadFile);
}
示例4: validate
/**
* @see Form::validate()
*/
public function validate()
{
parent::validate();
if (!empty($this->filename)) {
// import style
$this->style = StyleEditor::import($this->filename, PACKAGE_ID, $this->destinationStyle !== null && $this->destinationStyle->styleID ? $this->destinationStyle : null);
} else {
// import destination
if ($this->destinationStyle !== null && !$this->destinationStyle->styleID) {
throw new UserInputException('destinationStyleID');
}
// upload style
if ($this->styleUpload && $this->styleUpload['error'] != 4) {
if ($this->styleUpload['error'] != 0) {
throw new UserInputException('styleUpload', 'uploadFailed');
}
$this->newFilename = $this->styleUpload['tmp_name'];
try {
$this->styleData = StyleEditor::getStyleData($this->styleUpload['tmp_name']);
} catch (SystemException $e) {
throw new UserInputException('styleUpload', 'invalid');
}
// copy file
$newFilename = FileUtil::getTemporaryFilename('style_');
if (@move_uploaded_file($this->styleUpload['tmp_name'], $newFilename)) {
$this->newFilename = $newFilename;
}
} else {
if ($this->styleURL != 'http://') {
if (StringUtil::indexOf($this->styleURL, 'http://') !== 0) {
throw new UserInputException('styleURL', 'downloadFailed');
}
try {
$this->newFilename = FileUtil::downloadFileFromHttp($this->styleURL, 'style');
} catch (SystemException $e) {
throw new UserInputException('styleURL', 'downloadFailed');
}
try {
$this->styleData = StyleEditor::getStyleData($this->newFilename);
} catch (SystemException $e) {
throw new UserInputException('styleURL', 'invalid');
}
} else {
throw new UserInputException('styleUpload');
}
}
}
}
示例5: extractEmbeddedThumbnail
/**
* Extracts the embedded thumbnail picture of a jpeg or tiff image
*
* @return string thumbnail
*/
protected function extractEmbeddedThumbnail()
{
if (!function_exists('exif_thumbnail')) {
return false;
}
$width = $height = $type = 0;
$thumbnail = @exif_thumbnail($this->sourceFile, $width, $height, $type);
if ($thumbnail && $type && $width && $height) {
// resize the extracted thumbnail again if necessary
// (normally the thumbnail size is set to 160px
// which is recommended in EXIF >2.1 and DCF)
$this->mimeType = image_type_to_mime_type($type);
if (!$this->checkSize($width, $height)) {
// get temporary file name
$this->sourceFile = FileUtil::getTemporaryFilename('thumbnail_');
// create tmp file
$tmpFile = new File($this->sourceFile);
$tmpFile->write($thumbnail);
$tmpFile->close();
unset($thumbnail, $tmpFile);
// resize tmp file again
return $this->makeThumbnail(true);
}
return $thumbnail;
}
return false;
}
示例6: stripBoms
/**
* Strips supernumerous BOMs from a given bytestream.
*
* If we are dealing with bytestreams being pushed from one program or script to another in a UTF-8
* environment, we might encounter problems with BOMs (Byte Order Marks). E.g., if there's a script
* that reads a .tar file via readfile(), and this script is encoded in UTF-8, and being called from another
* script which wants to handle the bytestream that results from readfile(). But apparently because of the
* UTF-8 encoding of the called script -- at least in some PHP versions -- readfile() adds a UTF-8 BOM
* at the beginning of the bytestream. If we do write this bytestream to disk and then try to open the
* resulting file, we will get an error because it is no more a valid .tar archive. The same thing happens
* if we handle an .xml file and then try to parse it.
* So, if bytestreams are being handled in a UTF-8 environment, be sure always to use this function
* before writing the bytestream to disk or trying to parse it with an xml parser.
* This works regardless of multibyte string support (mb_strpos and friends) being enabled or not.
*
* Btw, if you try to apply the following to a bytestream read from a .tar file,
* you will end up with a file sized zero bytes:
* while (($byte = fgetc($fileHandle)) !== false) {
* fwrite($fileHandle, $byte);
* }
*
* @param string $sourceContent
* @param string $characterEncoding
* @return string destinationContent
*/
public static function stripBoms($sourceContent = '', $characterEncoding = 'UTF-8')
{
try {
// TODO: implement recognition of other BOMs (UTF-7, UTF-16 big endian, UTF-16 little endian etc.)
if ($characterEncoding == 'UTF-8') {
// get the ASCII codes for the three bytes the UTF-8 BOM is consisting of.
$firstByte = intval(0xef);
$secondByte = intval(0xbb);
$thirdByte = intval(0xbf);
} else {
return $sourceContent;
}
// put the bytestream's first three bytes to an array.
$workArray = array();
$workArray = unpack('C3', $sourceContent);
if (!is_array($workArray)) {
throw new SystemException("Unable to process bytestream.");
}
// detect the UTF-8 BOM.
$destinationContent = '';
if ($workArray['1'] == $firstByte && $workArray['2'] == $secondByte && $workArray['3'] == $thirdByte) {
$tmpname = FileUtil::getTemporaryFilename('stripBoms_');
$tmpStream = fopen($tmpname, 'w+');
fwrite($tmpStream, $sourceContent);
rewind($tmpStream);
// cut off the BOM.
fseek($tmpStream, 3);
// compatibility for PHP < 5.1.0
$destinationContent = stream_get_contents($tmpStream);
fclose($tmpStream);
@unlink($tmpname);
return $destinationContent;
} else {
return $sourceContent;
}
} catch (SystemException $e) {
throw $e;
}
}
示例7: validateUploadFile
/**
* Validates the upload file input.
*
* @throws UserInputException
*/
protected function validateUploadFile()
{
if (empty($this->uploadFile['tmp_name'])) {
throw new UserInputException('uploadFile', 'uploadFailed');
}
$tmpFilename = FileUtil::getTemporaryFilename('subscriberImport_', '.csv');
if (@copy($this->uploadFile['tmp_name'], $tmpFilename)) {
@unlink($this->uploadFile['tmp_name']);
$this->uploadFile['tmp_name'] = $tmpFilename;
}
}
示例8: downloadPackage
/**
* Tries to download a package from available update servers.
*
* @param string $package package identifier
* @param array $packageUpdateVersions package update versions
* @return string tmp filename of a downloaded package
*/
protected function downloadPackage($package, $packageUpdateVersions)
{
// get download from cache
if ($filename = $this->getCachedDownload($package, $packageUpdateVersions[0]['package'])) {
return $filename;
}
// download file
$authorizationRequiredException = array();
$systemExceptions = array();
foreach ($packageUpdateVersions as $packageUpdateVersion) {
try {
// get auth data
$authData = self::getAuthData($packageUpdateVersion);
// send request
if (!empty($packageUpdateVersion['file'])) {
$response = self::sendRequest($packageUpdateVersion['file'], array(), $authData);
} else {
$response = self::sendRequest($packageUpdateVersion['server'], array('packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']), $authData);
}
// check response
// check http code
if ($response['httpStatusCode'] == 401) {
throw new PackageUpdateAuthorizationRequiredException($packageUpdateVersion['packageUpdateServerID'], !empty($packageUpdateVersion['file']) ? $packageUpdateVersion['file'] : $packageUpdateVersion['server'], $response);
}
if ($response['httpStatusCode'] != 200) {
throw new SystemException(WCF::getLanguage()->get('wcf.acp.packageUpdate.error.downloadFailed', array('$package' => $package)) . ' (' . $response['httpStatusLine'] . ')', 18009);
}
// write content to tmp file
$filename = FileUtil::getTemporaryFilename('package_');
$file = new File($filename);
$file->write($response['content']);
$file->close();
unset($response['content']);
// test package
$archive = new PackageArchive($filename);
$archive->openArchive();
$archive->getTar()->close();
// cache download in session
$this->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename);
return $filename;
} catch (PackageUpdateAuthorizationRequiredException $e) {
$authorizationRequiredException[] = $e;
} catch (SystemException $e) {
$systemExceptions[] = $e;
}
}
if (count($authorizationRequiredException)) {
throw array_shift($authorizationRequiredException);
}
if (count($systemExceptions)) {
throw array_shift($systemExceptions);
}
return false;
}
示例9: export
/**
* Exports this style.
*
* @param boolean $templates
* @param boolean $images
* @param boolean $icons
*/
public function export($templates = false, $images = false, $icons = false)
{
// create style tar
require_once WCF_DIR . 'lib/system/io/TarWriter.class.php';
$styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz');
$styleTar = new TarWriter($styleTarName, true);
// append style preview image
if ($this->image && @file_exists(WCF_DIR . $this->image)) {
$styleTar->add(WCF_DIR . $this->image, '', FileUtil::addTrailingSlash(dirname(WCF_DIR . $this->image)));
}
// create style info file
$string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE style SYSTEM \"http://www.woltlab.com/DTDs/SXF/style.dtd\">\n<style>\n";
// general block
$string .= "\t<general>\n";
$string .= "\t\t<stylename><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleName) : $this->styleName) . "]]></stylename>\n";
// style name
if ($this->styleDescription) {
$string .= "\t\t<description><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleDescription) : $this->styleDescription) . "]]></description>\n";
}
// style description
if ($this->styleVersion) {
$string .= "\t\t<version><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleVersion) : $this->styleVersion) . "]]></version>\n";
}
// style version
if ($this->styleDate) {
$string .= "\t\t<date><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleDate) : $this->styleDate) . "]]></date>\n";
}
// style date
if ($this->image) {
$string .= "\t\t<image><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', basename($this->image)) : basename($this->image)) . "]]></image>\n";
}
// style preview image
if ($this->copyright) {
$string .= "\t\t<copyright><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->copyright) : $this->copyright) . "]]></copyright>\n";
}
// copyright
if ($this->license) {
$string .= "\t\t<license><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->license) : $this->license) . "]]></license>\n";
}
// license
$string .= "\t</general>\n";
// author block
$string .= "\t<author>\n";
if ($this->authorName) {
$string .= "\t\t<authorname><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->authorName) : $this->authorName) . "]]></authorname>\n";
}
// author name
if ($this->authorURL) {
$string .= "\t\t<authorurl><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->authorURL) : $this->authorURL) . "]]></authorurl>\n";
}
// author URL
$string .= "\t</author>\n";
// files block
$string .= "\t<files>\n";
$string .= "\t\t<variables>variables.xml</variables>\n";
// variables
if ($templates && $this->templatePackID) {
$string .= "\t\t<templates>templates.tar</templates>\n";
}
// templates
if ($images) {
$string .= "\t\t<images>images.tar</images>\n";
}
// images
if ($icons) {
$string .= "\t\t<icons>icons.tar</icons>\n";
}
// icons
$string .= "\t</files>\n";
$string .= "</style>";
// append style info file to style tar
$styleTar->addString(self::INFO_FILE, $string);
unset($string);
// create variable list
$string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE variables SYSTEM \"http://www.woltlab.com/DTDs/SXF/variables.dtd\">\n<variables>\n";
// get variables
$variables = $this->getVariables();
$exportImages = array();
foreach ($variables as $name => $value) {
// search images
if ($images && $value) {
if (preg_match_all('~([^/\\s\\$]+\\.(?:gif|jpg|jpeg|png))~i', $value, $matches)) {
$exportImages = array_merge($exportImages, $matches[1]);
}
}
$string .= "\t<variable name=\"" . StringUtil::encodeHTML($name) . "\"><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $value) : $value) . "]]></variable>\n";
}
$string .= "</variables>";
// append variable list to style tar
$styleTar->addString('variables.xml', $string);
unset($string);
if ($templates && $this->templatePackID) {
require_once WCF_DIR . 'lib/data/template/TemplatePack.class.php';
//.........这里部分代码省略.........
示例10: validateFile
/**
* Validates upload file.
*/
protected function validateFile()
{
$savedSmilies = 0;
WCF::getTPL()->assignByRef('savedSmilies', $savedSmilies);
// upload smiley(s)
if ($this->upload && $this->upload['error'] != 4) {
if ($this->upload['error'] != 0) {
throw new UserInputException('upload', 'uploadFailed');
}
// try to open file as an archive
if (preg_match('/(?:tar\\.gz|tgz|tar)$/i', $this->upload['name'])) {
$errors = array();
$tar = new Tar($this->upload['tmp_name']);
foreach ($tar->getContentList() as $file) {
if ($file['type'] != 'folder') {
// extract to tmp dir
$tmpname = FileUtil::getTemporaryFilename('smiley_');
$tar->extract($file['index'], $tmpname);
try {
// find filename
$i = 0;
$destination = WCF_DIR . 'images/smilies/' . basename($file['filename']);
while (file_exists($destination)) {
$destination = preg_replace('/((?=\\.[^\\.]*$)|(?=$))/', '_' . ++$i, $destination, 1);
}
// save
$this->smileyIDs[] = SmileyEditor::create($tmpname, $destination, 'upload', null, null, $this->showOrder ? $this->showOrder : null, $this->smileyCategoryID)->smileyID;
$savedSmilies++;
} catch (UserInputException $e) {
$errors[] = array('filename' => $file['filename'], 'errorType' => $e->getType());
}
}
}
$tar->close();
@unlink($this->upload['tmp_name']);
if (count($errors)) {
throw new UserInputException('upload', $errors);
} else {
if ($savedSmilies == 0) {
throw new UserInputException('upload', 'emptyArchive');
}
}
} else {
$this->validateTitle();
$this->validateCode();
// import as image file
$this->smileyIDs[] = SmileyEditor::create($this->upload['tmp_name'], WCF_DIR . 'images/smilies/' . basename($this->upload['name']), 'upload', $this->title, $this->code, $this->showOrder ? $this->showOrder : null, $this->smileyCategoryID)->smileyID;
$savedSmilies++;
}
} else {
if (!empty($this->filename)) {
if (!file_exists($this->filename)) {
throw new UserInputException('filename', 'notFound');
}
// copy smileys from a dir
if (is_dir($this->filename)) {
$errors = array();
$this->filename = FileUtil::addTrailingSlash($this->filename);
$handle = opendir($this->filename);
while (($file = readdir($handle)) !== false) {
if ($file != '.' && $file != '..' && is_file($this->filename . $file)) {
try {
// find filename
$i = 0;
$destination = WCF_DIR . 'images/smilies/' . $file;
while (file_exists($destination)) {
$destination = preg_replace('/((?=\\.[^\\.]*$)|(?=$))/', '_' . ++$i, $destination, 1);
}
// save
$this->smileyIDs[] = SmileyEditor::create($this->filename . $file, $destination, 'filename', null, null, $this->showOrder ? $this->showOrder : null, $this->smileyCategoryID)->smileyID;
$savedSmilies++;
} catch (UserInputException $e) {
$errors[] = array('filename' => $this->filename . $file, 'errorType' => $e->getType());
}
}
}
if (count($errors)) {
throw new UserInputException('filename', $errors);
} else {
if ($savedSmilies == 0) {
throw new UserInputException('filename', 'emptyFolder');
}
}
} else {
$this->validateTitle();
$this->validateCode();
$this->smileyIDs[] = SmileyEditor::create($this->filename, WCF_DIR . 'images/smilies/' . basename($this->filename), 'filename', $this->title, $this->code, $this->showOrder ? $this->showOrder : null, $this->smileyCategoryID)->smileyID;
$savedSmilies++;
}
} else {
throw new UserInputException('upload');
}
}
}
示例11: getBody
/**
* Creates the Body (Message, Attachments) for the Mail
* Returns the created Body to the function which invoke this class
*
* @return string mail body
*/
public function getBody()
{
$counter = 1;
$this->body = '';
if (count($this->getAttachments())) {
// add message
$this->body .= '--' . $this->getBoundary() . self::$crlf;
$this->body .= 'Content-Type: ' . $this->getContentType() . '; charset="' . CHARSET . '"' . self::$crlf;
$this->body .= 'Content-Transfer-Encoding: 8bit' . self::$crlf;
//$this->body .= self::$crlf.self::$crlf;
$this->body .= self::$crlf;
// wrap lines after 70 characters
$this->body .= wordwrap($this->getMessage(), 70);
$this->body .= self::$crlf . self::$crlf;
$this->body .= '--' . $this->getBoundary() . self::$crlf;
// add attachments
foreach ($this->getAttachments() as $attachment) {
$fileName = $attachment['name'];
$path = $attachment['path'];
// download file
if (FileUtil::isURL($path)) {
$tmpPath = FileUtil::getTemporaryFilename('mailAttachment_');
if (!@copy($path, $tmpPath)) {
continue;
}
$path = $tmpPath;
}
// get file contents
$data = @file_get_contents($path);
$data = chunk_split(base64_encode($data), 70, self::$crlf);
$this->body .= 'Content-Type: application/octetstream; name="' . $fileName . '"' . self::$crlf;
$this->body .= 'Content-Transfer-Encoding: base64' . self::$crlf;
$this->body .= 'Content-Disposition: attachment; filename="' . $fileName . '"' . self::$crlf . self::$crlf;
$this->body .= $data . self::$crlf . self::$crlf;
if ($counter < count($this->getAttachments())) {
$this->body .= '--' . $this->getBoundary() . self::$crlf;
}
$counter++;
}
$this->body .= self::$crlf . '--' . $this->getBoundary() . '--';
} else {
//$this->body .= self::$crlf;
$this->body .= $this->getMessage();
}
return $this->body;
}
示例12: unzipPackageArchive
/**
* Unzips compressed package archives.
*
* @param string $archive filename
* @return string new filename
*/
public static function unzipPackageArchive($archive)
{
if (!FileUtil::isURL($archive)) {
$tar = new Tar($archive);
$tar->close();
if ($tar->isZipped()) {
$tmpName = FileUtil::getTemporaryFilename('package_');
if (FileUtil::uncompressFile($archive, $tmpName)) {
return $tmpName;
}
}
}
return $archive;
}
示例13: validateUploadPackage
/**
* Validates the upload package input.
*/
protected function validateUploadPackage()
{
if (empty($this->uploadPackage['tmp_name'])) {
throw new UserInputException('uploadPackage', 'uploadFailed');
}
// try to unzip zipped package files
if (preg_match('!\\.(tar\\.gz|tgz)$!', basename($this->uploadPackage['name']))) {
$tmpFilename = FileUtil::getTemporaryFilename('package_', '.tar');
if (FileUtil::uncompressFile($this->uploadPackage['tmp_name'], $tmpFilename)) {
@unlink($this->uploadPackage['tmp_name']);
$this->uploadPackage['tmp_name'] = $tmpFilename;
}
} else {
$tmpFilename = FileUtil::getTemporaryFilename('package_', '.tar');
if (@copy($this->uploadPackage['tmp_name'], $tmpFilename)) {
@unlink($this->uploadPackage['tmp_name']);
$this->uploadPackage['tmp_name'] = $tmpFilename;
}
}
$this->archive = new PackageArchive($this->uploadPackage['tmp_name'], $this->package);
$this->validateArchive('uploadPackage');
}
示例14: writeDummyFile
/**
* Writes a dummy file in the selected ftp directory.
* Returns the file of the dummy file or null on failure.
*
* @param FTP $ftp
* @return string $filename
*/
protected static function writeDummyFile(FTP $ftp)
{
$dummyUploadFile = FileUtil::getTemporaryFilename('ftpDummy_', '.dat');
@touch($dummyUploadFile);
$destFile = FileUtil::removeLeadingSlash(strrchr($dummyUploadFile, '/'));
if (@(!$ftp->put($destFile, $dummyUploadFile, FTP_ASCII))) {
@unlink($dummyUploadFile);
return null;
}
@unlink($dummyUploadFile);
return $destFile;
}
示例15: checkDiffType
/**
* Every call to this function handles processing of a single patch out of the respective diff.
* For every hunk contained in this patch, a new instance of TemplatePatchUnified which handles
* the actual application of of a single hunk is called.
*
* @param integer $patchNo
*/
protected function checkDiffType($patchNo = 0)
{
// needed for checking range information lines of each hunk in the unified diff syntax.
$regexCheckHunk = "%^(\\s*)(\\@\\@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? \\@\\@)\$%";
$isUnifiedDiff = false;
$hunk = array();
$hunkNo = 0;
$this->patchNo = $patchNo;
// create a filehandle to the output file.
if (!($this->tempOutputFile = FileUtil::getTemporaryFilename('patchOutput_'))) {
throw new TemplatePatchException("Can't create tempfile for output.", 20001);
}
if (!($this->outputFileHandle = fopen($this->tempOutputFile, 'wb+'))) {
throw new TemplatePatchException("Can't open tempfile for output.", 20002);
}
// go through the lines of the patchfile.
foreach ($this->lines as $key => $line) {
// if this really is a unified diff, we start processing the contents of the patchfile.
// other diff types are not being supported at present.
if (preg_match($regexCheckHunk, $line, $result) == 1) {
if ($this->rePatch === false && $this->reverse === false) {
array_push($this->patch[$this->patchNo]['patch'], $line);
}
// don't need this line anymore.
array_push($this->garbage, $line);
unset($this->lines[$key]);
$isUnifiedDiff = true;
// store diff info.
if (empty($result[4])) {
$result[4] = 1;
}
if (empty($result[6])) {
$result[6] = 1;
}
$diffInfo = array('space' => trim($result[1]), 'range' => trim($result[2]), 'i_start' => trim($result[3]), 'i_lines' => trim($result[4]), 'o_start' => trim($result[5]), 'o_lines' => trim($result[6]));
// build the array needed for checking the end of each addition/deletion lines block
// within the respective diff.
$saw = array(' ' => 0, '+' => 0, '-' => 0);
// checks if a diff line is an addition line or a deletion line.
$regex = "/^" . $diffInfo['space'] . "([ +-])/";
foreach ($this->lines as $subkey => $diffline) {
// if this is an addition line or a deletion line, we store it into a special array.
if (preg_match($regex, $diffline, $result) && $diffline == preg_replace($regex, $result[1], $diffline)) {
if ($this->rePatch === false && $this->reverse === false) {
array_push($this->patch[$this->patchNo]['patch'], $diffline);
} elseif ($this->reverse === true) {
// inverse the indicator characters of the presumable hunk lines.
$diffline = preg_replace_callback("/^(\\+|\\-)/", create_function('$match', 'return $match[1] == "+" ? "-" : "+";'), $diffline);
}
// add this line to the hunks array.
array_push($hunk, $diffline);
unset($this->lines[$subkey]);
// stop this if we're at the end of this patch.
$saw[$result[1]]++;
if ($saw['-'] + $saw[' '] == $diffInfo['i_lines'] && $saw['+'] + $saw[' '] == $diffInfo['o_lines']) {
break;
}
} else {
continue;
}
}
// if the name of the file that's about to be patched has been omitted in the http request
// calling this class, we will try to read this filename from the diff file.
if ($this->rePatch === false && $this->reverse === false) {
$this->originalFile = $this->rummage();
} else {
$this->originalFile = $this->getTemplatePath();
}
// @todo: make sure to fclose all filehandles after processing!
// get a filehandle to the original file.
if (!($this->inputFileHandle = fopen($this->originalFile, 'rb'))) {
throw new TemplatePatchException("Can't open original file " . $this->originalFile . ".", 20003, $this->originalFile);
}
// attempt to apply this hunk.
$hunkNo = $hunkNo + 1;
$this->templatePatchUnified = new TemplatePatchUnified($this->originalFile, $this->inputFileHandle, $this->outputFileHandle, $diffInfo, $hunk, $hunkNo, $this->targetPosition, $this->fuzzFactor);
// remember the byte position in the target.
$this->targetPosition = $this->templatePatchUnified->i_pos;
// @todo: replace variable names in the PatchUnified like this one
// with better ones according to our coding style.
$hunk = array();
} else {
// lines that are neither context nor diff lines are being omitted.
array_push($this->garbage, $line);
unset($this->lines[$key]);
}
}
// there is no correct range information line, so we can't be sure that this is a unified patch.
if ($isUnifiedDiff === false) {
throw new TemplatePatchException("This is not a unified diff -- aborting.", 20004);
} else {
if ($this->rePatch === false && $this->reverse === false && isset($this->patch[$patchNo])) {
// save the applied patches to the database (with comments and blank lines omitted).
//.........这里部分代码省略.........