免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2686 | 回复: 0
打印 上一主题 下一主题

php检查上传文件是否已存在或同名 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-15 13:32 |只看该作者 |倒序浏览
php检查上传文件是否已存在或同名



.//检查上传文件的目录里是否已存在同名的上传文件


Php代码
  1. function searchFile($path,$file){
  2.         $file_array=array(); //存放文件名数组
  3.         $folder_array=array(); //存放目录名数组
  4.         $all_array=array(); //存放全部路径的数组

  5.         if(is_dir($path)){  //检查文件目录是否存在
  6.                 $H = @ opendir($path);
  7.                 while(false !== ($_file=readdir($H))){
  8.                         //检索目录
  9.                         if(is_dir($path."/".$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){
  10.                                 if(eregi('/'.$file,'/'.$_file)){
  11.                                         array_push($folder_array,$path."/".$_file);
  12.                                 }
  13.                                 searchFile($path."/".$_file,$file);
  14.                         //检索文件
  15.                         }elseif(is_file($path."/".$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
  16.                                 echo $_file;
  17.                                 echo '<br>';
  18.                                 //$_file = auto_charset($_file,'utf-8','gbk');
  19.                                 if(eregi('/'.$file,'/'.$_file)){
  20.                                         array_push($file_array,$path."/".$_file);
  21.                                         return 'yes'; //文件存在
  22.                                 }
  23.                         }
  24.                 }
  25.                 //$this->all_array["folder"]=$this->folder_array;
  26.                 //$this->all_array["file"]=$this->file_array;
  27.                 closedir($H);
  28.                 return 'no'; //不存在
  29.         }elseif(is_file($path)){
  30.                 if(eregi($file,$path)){
  31.                         //$this->all_array["file"]=$path;
  32.                         return 'yes'; //文件存在
  33.                 } else {
  34.                         return 'no'; //文件不存在
  35.                 }
  36.         }else{
  37.                 return 'no'; //文件不存在
  38.         }
  39. }  
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP