Check If File Exists In Php


Answer :

if (!file_exists('http://example.com/images/thumbnail_1286954822.jpg')) {    $filefound = '0'; } 

  1. The function expects a string.

  2. file_exists() does not work properly with HTTP URLs.


file_exists checks whether a file exist in the specified path or not.

Syntax:

file_exists ( string $filename ) 

Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.

$filename = BASE_DIR."images/a/test.jpg"; if (file_exists($filename)){     echo "File exist."; }else{     echo "File does not exist."; } 

Another alternative method you can use getimagesize(), it will return 0(zero) if file/directory is not available in the specified path.

if (@getimagesize($filename)) {...} 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?