Home > Backend Development > PHP Tutorial > Example of php automatically renaming files

Example of php automatically renaming files

WBOY
Release: 2016-07-25 08:52:32
Original
1048 people have browsed it
  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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template