您好,欢迎访问一九零五行业门户网

上传文件判断文件名是否重复

上传文件判断文件名是否重复请指教
上传文件时候如何判断 文件名重复?
上传文件我知道
$_files[表单名字]
$_files[表单名字][name]名字
如何获取上传路径文档里面的图片名字?
name = $file[name];
$this->type = $file[type];
$this->size = $file[size];
$this->tempdirectory = $file[tmp_name];
$this->directory = ../image/.$this->name;
$this->allowtype = array(
'image/jpg',
  'image/png',
  'image/gif',
  'image/pjpeg'
);
$this->error = $file[error];
  }
function isupfile(){ //是否有文件 1或0 1代表有
return is_uploaded_file($this->tempdirectory);
}
function movefile(){ //文件移动
move_uploaded_file($this->tempdirectory,$this->directory);
}
function iftype(){ //检查文件类型 unlink(路径);//文件删除方法
if(in_array($this->type,$this->allowtype)){
return true;
}else{
return false;
}
}
function ifname(){
//如何判断上传的文件名与已上传的文件名重复
}
}
?>
上传文件模块
------解决方案--------------------
$file=$_files[表单名字][name];
if(file_exists($file))
echo 'exist';
else
move_uploaded_file()........
------解决方案--------------------
if(file_exists($this->tempdirectory)) echo '文件已存在';
------解决方案--------------------
按照规则先生成绝对路径,然后就能知道该路径下的文件是否存在了呗...
不过这种做法很不安全,建议还是完全随机的文件名。
------解决方案--------------------
探讨
$file=$_files[表单名字][name];
if(file_exists($file))
echo 'exist';
else
move_uploaded_file()........
其它类似信息

推荐信息