문제

Do you have any sample codes or functions to check if an image name is existing already in the folder before uploading? I've tried using file_exists() but it doesn't work, here is my sample code:

$path = FCPATH . "images2/";
$filename=$_FILE['userfile'];
$full_path = $path .$filename;
if(file_exists($filename))
{
///display error message///
}
도움이 되었습니까?

해결책 2

I'm assuming you are not getting the correct result with file_exists() because you don't include the full path (even tho you define it).

Try using the following: file_exists($full_path)

Also consider using some CI helper functions for handling files like images, or uploads. They are there to make this 'easier'.

File helper:
http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html

다른 팁

Here is the simplest way to check if a file exist:

if(is_file($filename){
    return true; //the file exist
}else{
    return false; //the file does not exist
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top