Reputation: 77
I have a project in CakePHP and I would like to know how to check if an image exists with the extension '.jpg' if not use the extension '.JPG', any help would be deeply appreciated.
Upvotes: 2
Views: 4022
Reputation: 166
my image path like app/webroot/img/upload/file123.jpg
WWW_ROOT define your webroot folder path and DS define '/'
$image='file123.jpg';
$file = WWW_ROOT . 'img' . DS . 'uploads' . DS . $image;
if conditions for file check
if(file_exists($file) && $image){
enter your code if file exists
}else{
file not exists
}
Upvotes: 0
Reputation: 166
$file = WWW_ROOT . 'img' . DS . 'uploads' . DS . 'file123.jpg';
Upvotes: 1
Reputation: 1588
bool file_exists ( string $filename )
Checks whether a file or directory exists. Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
http://php.net/manual/en/function.file-exists.php
Upvotes: 2