Brian Mayer
Brian Mayer

Reputation: 1019

PHP is_file() and file_exists() doesn't return true for existing PDF and SVG files

I don't know if this is an intrinsic property of the functions or something in my PHP configuration, but for some reason when I am using is_file() and file_exists() to confirm the existence of a PDF or SVG file with a global path (/home/brian/public_html/path/to/file.pdf) then it will return false even if the file is there.

Is there a reason this would happen for these filetypes?

Upvotes: 0

Views: 1280

Answers (1)

WiConDo
WiConDo

Reputation: 11

Ran into the the problem right away and found no other solution than using fopen():

if ($file = @fopen($file_path, 'rb')): // returns resource id if file exists
   //do whatever you like!
else:
   //file does not exist
endif;

Maybe not the cleanest solution, but it works for me

Upvotes: 1

Related Questions