PHP automatically renames the file implementation method,
In this paper, we explain how to implement PHP automatic renaming file. Share to everyone for your reference. The specific methods are analyzed as follows:
PHP Rename file name we often use in the actual development process, such as the user to upload files or some of the auto-generated cache file features we need to use the automatic renaming function. But in general, we are in the production of the upload file naming method is used to take the system current time plus the number of times in the way, this method is feasible but sometimes does not meet the needs of customers. Some customers ask us to name the file name in the same way as the Windows system, such as automatic serial number, such as uploading a name "new text document" When someone else uploads a file named "New text Document" We use the serial number name means that the second "new text document" named " New text Document (1) "When someone uploads a file with the same name again and so on."
Below to share a source to everyone:
Copy the Code code as follows: <?php
$file = DirName (__file__). ' /new text document. txt ';
echo L_rename ($file);
function L_rename ($file) {
$iCount = 0;
$File _type = STRRCHR ($file, '. ');
$FilePath = substr ($file, 0, Strrpos ($file, '. '));
while (true) {
if (Is_file ($file)) {
+ + $iCount;
$file = $FilePath. ' ('. $iCount. ') '. $File _type;
}else{
Break
}
}
if (fopen ($file, ' W ')) {$MSG = ' created successfully '. $file;}
return $MSG;
}
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/906110.html www.bkjia.com true http://www.bkjia.com/PHPjc/906110.html techarticle PHP Automatic Renaming file implementation method, this article describes the PHP automatic renaming file implementation method. Share to everyone for your reference. The specific method is analyzed as follows: Php rename file name ...