I have a piece of code shown in the screenshot that should check for the existence of a file. I am not sure why file_exists() doesn't return FALSE in case of non-existing files. I passed an empty string to the $this->get_custom_js_file_contents('') but the else block doesn't get the control. Please point out to me what is not right in it.

enter image description here


Check the documentation: https://www.php.net/manual/en/function.file-exists.php

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

You shouldn't use the file_exist() function to validate the directory path in your case. If you want to secure your script from executing when you pass empty filename just add condition on the beginning.

if (empty($js_file_name)) {
    return false;

Or use is_file() function.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.