Heim  >  Artikel  >  Backend-Entwicklung  >  php自动重命名文件的例子

php自动重命名文件的例子

WBOY
WBOYOriginal
2016-07-25 08:52:32999Durchsuche
  1. //自动重命名文件
  2. $file = dirname(__FILE__).'/新建 文本文档.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 = '创建成功 '.$file;}
  17. return $Msg;
  18. }
  19. ?>
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn