zoukankan      html  css  js  c++  java
  • 用php怎么改文件名

    php手册:
    bool rename ( string oldname, string newname [, resource context] )
    尝试把 oldname 重命名为 newname。
    如果成功则返回 TRUE,失败则返回 FALSE。
    例子:
    rename( 'tempFile.txt', 'tempFile2.txt' );

    <?php
    //$filedir = "upload";
    function showDir( $filedir ) {
    //打开目录
    $dir = @ dir($filedir);
    //列出目录中的文件
    $filename = time();
    while (($file = $dir->read())!==false)
      {
         if(is_dir($filedir."/".$file) AND ($file!=".") AND ($file!="..")) {
               showDir($filedir."/".$file);
          } else {
                if ($file != "." and $file != ".."){
                  $oldname = $filedir."/".$file;
                  echo "oldname: ".$oldname;
                  echo "<br />";
                  $end = strrpos($oldname, ".");
                  $file = substr_replace($oldname,$filename,0,$end);
                  $newfile = $filedir."/".$file;
                  echo "newfile :".$newfile;
                  rename($oldname,$newfile);
                  $filename++;
                  echo "<br />";
               }
          }
     }
    $dir->close();
    }
    showDir("app1");
    ?>

  • 相关阅读:
    保险实战
    单片机的应用(位操作)
    显示转换(类型转换)
    游泳池的容量
    消失的重量(隐式变换)
    物品交换(变量)
    物品的存放(变量)
    输出变量的界值(int、float、long.....)
    在屏幕上输出内容
    C#笔记
  • 原文地址:https://www.cnblogs.com/diony/p/4737020.html
Copyright © 2011-2022 走看看