Home  >  Article  >  Backend Development  >  Example of php automatically renaming files

Example of php automatically renaming files

WBOY
WBOYOriginal
2016-07-25 08:52:321046browse
  1. //Automatically rename files
  2. $file = dirname(__FILE__).'/New text document.txt';
  3. echo L_rename($file);
  4. function L_rename($file){
  5. $iCount = 0;
  6. $File_type = strrchr($file, '.');
  7. $FilePath = substr($file, 0, strrpos($file, '.'));
  8. while (true) {
  9. if (is_file($file)) {
  10. ++$iCount;
  11. $file = $FilePath . '('. $iCount .')' . $File_type;
  12. }else{
  13. break;
  14. }
  15. }
  16. if (fopen ($file, 'w')) {$Msg = 'Created successfully'.$file;}
  17. return $Msg;
  18. }
  19. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn