php创建文件时存在文件自动重命名实现方法
preg_match_all("/{$fileinfo['filename']}(d*).{$fileinfo['extension']}/i", $file, $match))
{
$max = max($match[1]);
if($max)
{
$createfile = $fileinfo['filename'] . ($max 1) . '.' . $fileinfo['extension'];
}
else
{
$createfile = $fileinfo['filename'] . '1.' . $fileinfo['extension'];
}
}
}
createfile($createfile);
}
else
{
createfile($filename);
}
?></blockquote>
使用临时文件作记数器 方法二
<blockquote><?php
function createfile($filename, $content = '')
{
if(file_exists($filename . '.tmp'))
{
$num = (int) file_get_contents($filename . '.tmp') 1;
$fileinfo = pathinfo($filename);
file_put_contents($fileinfo['filename'] . '(' . $num . ')' .$fileinfo['extension'], $content);
file_put_contents($filename . '.tmp', $num);
}
else
{
file_put_contents($filename, $content);
file_put_contents($filename . '.tmp', 1);
}
}
createfile('test.txt');
?>
您可能感兴趣的文章:
PHP新特性命名空间的详解介绍
php ftp类(上传、下载、复制、移动等)
VBS脚本运行库手册(5)-复制和移动文件
php基础教程之php文件操作概述
php ftp函数应用(范例,ftp类,创建目录函数等)
autorun.inf是什么文件?autorun.inf文件怎么删除?
php中命名空间学习基础知识记忆
浅析PHP类的自动加载和命名空间
PHP的命名空间使用详解
VBS脚本运行库手册(2)-管理文件夹