PHP Automatic Rename file implementation method, _php tutorial

Source: Internet
Author: User
Tags php programming

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.