Need help with the codeigniter, I think file_exists is for server path, not for url. but my image folder got same level with application and system folder. find nothing on google, please help
$url=base_url();
$filename="$url/upload/$id.jpg";
if (file_exists($filename)){
echo "<li><img src=\"".$url."upload/$id.jpg\" width=\"40\" height=\"40\" /></li>";
}else{
echo "<li><img src=\"http://www.mydomain.com/haha/image/noimg.png\" width=\"40\" height=\"40\" /></li>";
}
Codeigniter is always running on
index.php, so all paths are relative from there. You can use any of the following, assumingupload/is at the same level asindex.php:file_exists("upload/$id.jpg")file_exists("./upload/$id.jpg")file_exists(FCPATH."upload/$id.jpg")FCPATHis a constant that Codeigniter sets which contains the absolute path to yourindex.php.As a side note, I prefer
is_file()when checking files, asfile_exists()returns true on directories. In addition, you might want to see ifgetimagesize()returnsFALSEto make sure you have an image.