本文整理汇总了PHP中eZFile::rename方法的典型用法代码示例。如果您正苦于以下问题:PHP eZFile::rename方法的具体用法?PHP eZFile::rename怎么用?PHP eZFile::rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZFile
的用法示例。
在下文中一共展示了eZFile::rename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
static function create($filename, $directory = false, $data = false, $atomic = false)
{
$filepath = $filename;
if ($directory) {
if (!file_exists($directory)) {
eZDir::mkdir($directory, false, true);
// eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
}
$filepath = $directory . '/' . $filename;
}
// If atomic creation is needed we will use a temporary
// file when writing the data, then rename it to the correct path.
if ($atomic) {
$realpath = $filepath;
$dirname = dirname($filepath);
if (strlen($dirname) != 0) {
$dirname .= "/";
}
$filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
}
$file = fopen($filepath, 'wb');
if ($file) {
// eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
if ($data) {
if (is_resource($data)) {
// block-copy source $data to new $file in 1MB chunks
while (!feof($data)) {
fwrite($file, fread($data, 1048576));
}
fclose($data);
} else {
fwrite($file, $data);
}
}
fclose($file);
if ($atomic) {
// If the renaming process fails, delete the temporary file
eZFile::rename($filepath, $realpath, false, eZFile::CLEAN_ON_FAILURE);
}
return true;
}
// eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
return false;
}
示例2: preview
/**
* Creates the object from the uploaded file and displays the preview of it
*
* @param array $args
* @return array
* @throw RuntimeException if the previously uploaded file cannot be fetched
*/
static function preview( $args )
{
$http = eZHTTPTool::instance();
$handler = self::getHandler( $args );
if ( !$handler->canUpload() )
{
throw new RuntimeException(
ezpI18n::tr(
'extension/ezjscore/ajaxuploader',
'You are not allowed to upload a file.'
)
);
}
$file = $http->postVariable( 'UploadFile', false );
$fileHandler = eZClusterFileHandler::instance();
if ( $file === false
|| !$fileHandler->fileExists( $file )
|| !$fileHandler->fileFetch( $file ) )
{
throw new RuntimeException(
ezpI18n::tr(
'extension/ezjscore/ajaxuploader', 'Unable to retrieve the uploaded file.'
)
);
}
else
{
$tmpFile = eZSys::cacheDirectory() . '/' .
eZINI::instance()->variable( 'FileSettings', 'TemporaryDir' ) . '/' .
str_replace(
array( '/', '\\' ), '_',
$http->postVariable( 'UploadOriginalFilename' )
);
eZFile::rename( $file, $tmpFile, true );
$fileHandler->fileDelete( $file );
$fileHandler->fileDeleteLocal( $file );
}
$contentObject = $handler->createObject(
$tmpFile,
$http->postVariable( 'UploadLocation', false ),
$http->postVariable( 'UploadName', '' )
);
unlink( $tmpFile );
$tpl = eZTemplate::factory();
$tpl->setVariable( 'object', $contentObject );
return array(
'meta_data' => $handler->serializeObject( $contentObject ),
'html' => $tpl->fetch( 'design:ajaxuploader/preview.tpl' )
);
}
示例3: saveCache
/**
* Stores the content of the INI object to the cache file \a $cachedFile.
*
* @param string $cachedDir Cache dir, usually "var/cache/ini/"
* @param string $cachedFile Name of cache file as returned by cacheFileName()
* @param array $data Configuration data as an associative array structure
* @param array $inputFiles List of input files used as basis for cache (for use in load cache to check mtime)
* @param string $iniFile Ini file path string returned by findInputFiles() for main ini file
* @return bool
*/
protected function saveCache($cachedDir, $cachedFile, array $data, array $inputFiles, $iniFile)
{
if (!file_exists($cachedDir)) {
if (!eZDir::mkdir($cachedDir, 0777, true)) {
eZDebug::writeError("Couldn't create cache directory {$cachedDir}, perhaps wrong permissions", __METHOD__);
return false;
}
}
// Save the data to a temp cached file
$tmpCacheFile = $cachedFile . '_' . substr(md5(mt_rand()), 0, 8);
$fp = @fopen($tmpCacheFile, "w");
if ($fp === false) {
eZDebug::writeError("Couldn't create cache file '{$cachedFile}', perhaps wrong permissions?", __METHOD__);
return false;
}
// Write cache data as a php structure with some meta information for use while reading cache
fwrite($fp, "<?php\n// This is a auto generated ini cache file, time created:" . date(DATE_RFC822) . "\n");
fwrite($fp, "\$data = array(\n");
fwrite($fp, "'rev' => " . eZINI::CONFIG_CACHE_REV . ",\n");
fwrite($fp, "'created' => '" . date('c') . "',\n");
if ($this->Codec) {
fwrite($fp, "'charset' => \"" . $this->Codec->RequestedOutputCharsetCode . "\",\n");
} else {
fwrite($fp, "'charset' => \"{$this->Charset}\",\n");
}
fwrite($fp, "'files' => " . preg_replace("@\n[\\s]+@", '', var_export($inputFiles, true)) . ",\n");
fwrite($fp, "'file' => '{$iniFile}',\n");
fwrite($fp, "'val' => " . preg_replace("@\n[\\s]+@", '', var_export($data, true)) . ");");
fwrite($fp, "\n?>");
fclose($fp);
// Rename cache temp file to final desitination and set permissions
eZFile::rename($tmpCacheFile, $cachedFile);
chmod($cachedFile, self::$filePermission);
if (eZINI::isDebugEnabled()) {
eZDebug::writeNotice("Wrote cache file '{$cachedFile}'", __METHOD__);
}
return true;
}
示例4: close
function close()
{
if ($this->ClusteringEnabled) {
$this->ClusterHandler = null;
return;
}
if ($this->FileResource) {
fclose($this->FileResource);
if ($this->isAtomic) {
eZFile::rename($this->tmpFilename, $this->requestedFilename);
}
$this->FileResource = false;
}
}
示例5: clearMeta
function clearMeta()
{
$tmpFile = $this->MetaFileName . substr(md5(mt_rand()), 0, 8);
$content = array();
eZFile::create($tmpFile, false, serialize($content));
eZFile::rename($tmpFile, $this->MetaFileName);
}
示例6: fileMove
/**
* Move file.
*
* \public
* \static
*/
function fileMove($srcPath, $dstPath)
{
eZDebugSetting::writeDebug('kernel-clustering', "fs::fileMove( '{$srcPath}', '{$dstPath}' )", __METHOD__);
eZDebug::accumulatorStart('dbfile', false, 'dbfile');
eZFile::rename($srcPath, $dstPath, true);
eZDebug::accumulatorStop('dbfile');
}
示例7: _fetch
/**
* Fetches the file $filePath from the database to its own name
*
* Saving $filePath locally with its original name, or $uniqueName if given
*
* @param string $filePath
* @param string $uniqueName Alternative name to save the file to
* @return string|bool the file physical path, or false if fetch failed
*/
public function _fetch( $filePath, $uniqueName = false )
{
$metaData = $this->_fetchMetadata( $filePath );
if ( !$metaData )
{
// @todo Throw an exception
eZDebug::writeError( "File '$filePath' does not exist while trying to fetch.", __METHOD__ );
return false;
}
// create temporary file
if ( strrpos( $filePath, '.' ) > 0 )
$tmpFilePath = substr_replace( $filePath, getmypid().'tmp', strrpos( $filePath, '.' ), 0 );
else
$tmpFilePath = $filePath . '.' . getmypid().'tmp';
$this->__mkdir_p( dirname( $tmpFilePath ) );
// copy DFS file to temporary FS path
// @todo Throw an exception
if ( !$this->dfsbackend->copyFromDFS( $filePath, $tmpFilePath ) )
{
eZDebug::writeError("Failed copying DFS://$filePath to FS://$tmpFilePath ");
return false;
}
// Make sure all data is written correctly
clearstatcache();
$tmpSize = filesize( $tmpFilePath );
// @todo Throw an exception
if ( $tmpSize != $metaData['size'] )
{
eZDebug::writeError( "Size ($tmpSize) of written data for file '$tmpFilePath' does not match expected size " . $metaData['size'], __METHOD__ );
return false;
}
if ( $uniqueName !== true )
{
eZFile::rename( $tmpFilePath, $filePath, false, eZFile::CLEAN_ON_FAILURE | eZFile::APPEND_DEBUG_ON_FAILURE );
}
else
{
$filePath = $tmpFilePath;
}
return $filePath;
}
示例8: renameOnDFS
/**
* Renamed DFS file $oldPath to DFS file $newPath
*
* @param string $oldPath
* @param string $newPath
* @return bool
*/
public function renameOnDFS($oldPath, $newPath)
{
$this->accumulatorStart();
$oldPath = $this->makeDFSPath($oldPath);
$newPath = $this->makeDFSPath($newPath);
$ret = eZFile::rename($oldPath, $newPath, true);
if ($ret) {
eZClusterFileHandler::cleanupEmptyDirectories($oldPath);
}
$this->accumulatorStop();
return $ret;
}
示例9: rotateLog
static function rotateLog($fileName)
{
$maxLogrotateFiles = eZDebug::maxLogrotateFiles();
for ($i = $maxLogrotateFiles; $i > 0; --$i) {
$logRotateName = $fileName . '.' . $i;
if (@file_exists($logRotateName)) {
if ($i == $maxLogrotateFiles) {
@unlink($logRotateName);
// print( "@unlink( $logRotateName )<br/>" );
} else {
$newLogRotateName = $fileName . '.' . ($i + 1);
//include_once( 'lib/ezfile/classes/ezfile.php' );
eZFile::rename($logRotateName, $newLogRotateName);
// print( "@rename( $logRotateName, $newLogRotateName )<br/>" );
}
}
}
if (@file_exists($fileName)) {
$newLogRotateName = $fileName . '.' . 1;
//include_once( 'lib/ezfile/classes/ezfile.php' );
eZFile::rename($fileName, $newLogRotateName);
// print( "@rename( $fileName, $newLogRotateName )<br/>" );
return true;
}
return false;
}
示例10: move
function move($source, $destination)
{
append_to_log("Source: {$source} Destination: {$destination}");
// Make real path to source and destination.
$realSource = $_SERVER["DOCUMENT_ROOT"] . $source;
$realDestination = $_SERVER["DOCUMENT_ROOT"] . $destination;
append_to_log("RealSource: {$realSource} RealDestination: {$realDestination}");
$status = eZFile::rename($realSource, $realDestination);
if ($status) {
append_to_log("move was OK");
return eZWebDAVServer::OK_CREATED;
} else {
append_to_log("move FAILED");
return eZWebDAVServer::FAILED_CONFLICT;
}
}
示例11: nextConnection
} else {
if (count($serverlist) > 1) {
// retrying other server
$active_server = nextConnection($active_server, $serverlist, $i + 1);
$smtp = getConnection($active_server, $serverlist);
$try = 1;
while (!$smtp->send($from, $to, $email) && $try <= $maxRetry) {
$active_server = nextConnection($active_server, $serverlist, $i + 1);
$smtp = getConnection($active_server, $serverlist);
$try++;
}
if ($try == $maxRetry) {
eZFile::rename($mailFiles[$i - 1], $mailFiles[$i] . ".notsend");
}
} else {
eZFile::rename($mailFiles[$i - 1], $mailFiles[$i] . ".notsend");
}
}
}
if ($robinCounter >= $packageSize && count($serverlist) != 1) {
$time_end = microtime_float2();
$time = $time_end - $time_start;
$cli->output("Sent " . $robinCounter . " emails in " . number_format($time, 3) . " seconds with " . $serverlist[$active_server]['host']);
$cli->output("Average speed: " . number_format((double) 60.0 * (double) $robinCounter / (double) $time, 3) . " emails/minute");
$robinCounter = 0;
$active_server = nextConnection($active_server, $serverlist, $i + 1);
$time_start = microtime_float2();
}
if (eZMail::validate($from) && eZMail::validate($to)) {
$robinCounter++;
}
示例12: rotateLog
private function rotateLog($fileName)
{
for ($i = $this->maxLogRotateFiles; $i > 0; --$i) {
$logRotateName = $fileName . '.' . $i;
if (@file_exists($logRotateName)) {
if ($i == $this->maxLogRotateFiles) {
@unlink($logRotateName);
} else {
$newLogRotateName = $fileName . '.' . ($i + 1);
eZFile::rename($logRotateName, $newLogRotateName);
}
}
}
if (@file_exists($fileName)) {
$newLogRotateName = $fileName . '.' . 1;
eZFile::rename($fileName, $newLogRotateName);
return true;
}
return false;
}
示例13: glob
$appsDir = glob($oldAppsDir . '/*', GLOB_ONLYDIR);
foreach($appsDir as $appDir) {
$parts = explode('/', rtrim($appDir, '/'));
$appIdentifier = array_pop($parts);
$icons = glob($appDir . '/ico*');
foreach($icons as $icon) {
$iconName = basename($icon);
if (in_array($iconName, $iconsToMove)) {
moveIfNeeded($icon, eZDir::path(array($newAppsDir, $appIdentifier, $iconName)));
}
}
}
if ($remove) {
foreach(array_unique($fileToRemove) as $file) {
eZFile::rename($file, 'var/image_refactor_save/' . ltrim($file, '/'), true, eZFile::APPEND_DEBUG_ON_FAILURE);
$oldFolder = trim(dirname($file));
$parts = explode('/', $oldFolder);
$files = glob($oldFolder . '/*');
if (count($parts) >= 5 && count($files) == 0) {
$cli->notice('Remove ' . $oldFolder);
rmdir($oldFolder);
}
}
}
$script->shutdown();
示例14: endCacheGeneration
/**
* Ends the cache generation started by startCacheGeneration().
*
* If $rename is set to true (default), the .generating file is renamed and
* overwrites the real file.
* If set to false, the .generating file is removed, and the real file made
* available.
*
* True should be used when actual data is stored in the standard file and
* not the .generating one, for instance when using image alias generation.
*
* @param bool $rename Rename (true) or delete (false) the generating file
*
* @return bool
**/
public function endCacheGeneration($rename = true)
{
eZDebug::accumulatorStart('dbfile', false, 'dbfile');
$ret = false;
eZDebugSetting::writeDebug("kernel-clustering", $this->realFilePath, __METHOD__);
// rename the file to its final name
if ($rename === true) {
if (eZFile::rename($this->filePath, $this->realFilePath)) {
$this->filePath = $this->realFilePath;
$this->realFilePath = null;
$this->remainingCacheGenerationTime = false;
$ret = true;
} else {
eZLog::write("eZFS2FileHandler::endCacheGeneration: Failed renaming '{$this->filePath}' to '{$this->realFilePath}'", 'cluster.log');
}
} else {
unlink($this->filePath);
$this->filePath = $this->realFilePath;
$this->realFilePath = null;
}
eZDebug::accumulatorStop('dbfile');
return $ret;
}
示例15: create
static function create($filename, $directory = false, $data = false, $atomic = false)
{
$filepath = $filename;
if ($directory) {
if (!file_exists($directory)) {
eZDir::mkdir($directory, false, true);
// eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
}
$filepath = $directory . '/' . $filename;
}
// If atomic creation is needed we will use a temporary
// file when writing the data, then rename it to the correct path.
if ($atomic) {
$realpath = $filepath;
$dirname = dirname($filepath);
if (strlen($dirname) != 0) {
$dirname .= "/";
}
$filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
}
$file = fopen($filepath, 'wb');
if ($file) {
// eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
if ($data) {
fwrite($file, $data);
}
fclose($file);
if ($atomic) {
eZFile::rename($filepath, $realpath);
}
return true;
}
// eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
return false;
}