在上传之前,您是否有任何示例代码或函数来检查文件夹中是否已存在图像名称? 我尝试过使用file_exists()但是它不起作用,这是我的示例代码:
$path = FCPATH . "images2/";
$filename=$_FILE['userfile'];
$full_path = $path .$filename;
if(file_exists($filename))
{
///display error message///
}
答案 0 :(得分:1)
以下是检查文件是否存在的最简单方法:
if(is_file($filename){
return true; //the file exist
}else{
return false; //the file does not exist
}
答案 1 :(得分:0)
我假设您没有使用file_exists()
获得正确的结果,因为您没有包含完整路径(即使您定义它)。
尝试使用以下内容:file_exists($full_path)
还要考虑使用一些CI帮助程序函数来处理图像或上传等文件。他们在那里使这更“容易”。
文件助手:
http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html