hectorviov
hectorviov

Reputation: 77

Check if an image exists on cakephp

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

Answers (3)

Digpal Singh
Digpal Singh

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

Digpal Singh
Digpal Singh

Reputation: 166

$file = WWW_ROOT . 'img' . DS . 'uploads' . DS . 'file123.jpg';

Upvotes: 1

kotekzot
kotekzot

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

Related Questions