PHP automatic file rename implementation method, _ PHP Tutorial

Source: Internet
Author: User
PHP automatically rename the file implementation method ,. PHP automatic file rename implementation method. This article describes how to implement PHP automatic file rename. Share it with you for your reference. The specific method is as follows: PHP rename file name PHP automatic rename file implementation method,

This example describes how to automatically rename a file in PHP. Share it with you for your reference. The specific method is analyzed as follows:

PHP rename file names are often used in actual development. for example, you need to use the automatic rename function to upload files or automatically generate cached files. However, when creating and uploading files, we usually use the method of getting the current time of the system plus the number of files at any time. This method is feasible, but sometimes it cannot meet the needs of customers. Some customers require that our file names be named in the same way as the windows system, for example, upload a file named "New Text Document". when another person uploads a file named "New Text Document", we use the serial number to name it, which means that the second "new text document" is automatically created" name it "new text document (1) "When someone uploads a file with the same name, and so on.
The following is a source code:

The code is as follows:

<? Php
$ File = dirname (_ FILE _). '/create a text file. 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 will help you with PHP programming.




Example: how to automatically rename a file in PHP. Share it with you for your reference. The detailed analysis method is as follows: PHP rename the file name...

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.