rename(原来的名字,修改后的名字)
名字的路径也要写完整

解决方案 »

  1.   

    bool rename( string oldname, string newname)
      

  2.   

    我是过了,不行。
    oldname,newname     都是文件名不行。
    oldname,newname     都是带虚拟目录的文件名还是不行。
    我的虚拟目录为   "   ../php111    "
    是不是虚拟目录的缘故?
      

  3.   

    rename( string oldname, string newname)
    oldname,newname     都是带虚拟目录的文件名还是不行。
    出现
    Warning: Rename failed (Invalid argument) in C:\apache\htdocs\rjb\xb\upload_1.php3 on line 74
    错误。
      

  4.   

    代码如下:
    <form enctype="multipart/form-data" name="submitform" action="upload_1.php3" method="post">
            <input type="hidden" name="max_file_size" value="1000000">
            <input type="hidden" name="uploadaction" value="1">
    ..............................
    <td width="76">添加文件</td>
              <td width="316"> 
                <input name="uploadfile" type="file" size="30"></td>    
       </tr> 
     <td width="76" >  
      <input name="submit" value="提交" type="submit"></td>
    ------upload_1.php3代码----------
    .........
    $uploadaction=0;
    $timelimit=600;
    $date=date("h:i:s A");
    set_time_limit($timelimit);
    if(($uploadfile!="none")&&(uploadfile!=""))
    { $uploadpath="../php111/";
       $uploadfile_name1.=$date;
    $filename  =$uploadpath.$uploadfile_name;
    $ext=substr($filename,strrpos($filename,".")+1);
    //echo $ext;得出文件扩展名
    $wjm=$date;
    $point=".";
    $wjm.=$point;
    $wjm.=$ext;
    //echo $wjm;   //重新命名文件,利用上传时间+“.”+原扩展名
    $path1=substr($filename,strrpos($filename,"/")+1);//得到最右边的"/"之后的字符串儿
    if($uploadfile_size<1024)
    {
    $filesize=(string)$uploadfile_size."字节";
    }
    elseif($uploadfile_size<(1024*1024))
    {
    $filesize=number_format((double)($uploadfile_size/1024),1)."KB";
    }
    else
    {
    $filesize=number_format((double)($uploadfile_size/(1024*1024)),1)."MB";
    }
    if(!file_exists($filename))
    {
    if (copy($uploadfile,$filename))
    {
                            $order_file=$uploadpath;
    $order_file.=$wjm;
    //echo $order_file; 在新生成的文件前加上虚拟路径
     rename($filename,$order_file);
                     echo "文件 $uploadfile_name($filesize)上载成功!";
    }
     else
    { ?>
    <script language="javascript">
        alert("上载失败,请核实!")
      history.go(-1)
      </script> <? }
    unlink($uploadfile);
     }
    ........
    运行后出现上面的错误。
    帮我看看,谢谢!
      

  5.   

    我的思路:
    ..................
    得到上传文件——〉取其文件扩展名——〉得到上传时间,在时间后面加上扩展名——〉得到虚拟目录(文件上传到的文件夹 "../php111")——〉把新建的文件名+虚拟目录 (两者相结合)——〉在传过来的文件进行重命名
    ..................
    明白吗?
      

  6.   

    好长呀
    你直接将rename($filename,$order_file);里面的参数echo 出来看看吧
      

  7.   

    我echo 过
    分别是  .../php111/abcd.gif
            .../php111/11:24:39 AM.gif
    感觉没问题呀
      

  8.   

    .../php111/11:24:39 AM.gif
    这里面不是有两个: