Q:

PHP file_exists if/then statement

This is my first time playing with PHP, and I'm having trouble making a basic if/then statement. I want to do something like
if file exists
 show the html code 
else
 show different html code. 
Here's where I'm at currently -- 
<?php
if ( file_exists('pdf/'.'htmlspecialchars($_POST['apt'], ENT_COMPAT)'.'.pdf') {
    echo "the file exists";
}  else {
    echo "file does not exist";
}
?>

I think the problem here is how I wrote the
file_exists('pdf/'.'htmlspecialchars($_POST['apt'], ENT_COMPAT)'.'.pdf')

Thoughts greatly appreciated!

A:

Try with:
if (file_exists('pdf/' . htmlspecialchars($_POST['apt'], ENT_COMPAT) . '.pdf')) {
    echo "the file exists";
} else {
    echo "file does not exist";
}

You had some quotes before calling htmlspecialchars(). When you call a function you don't need quotes.
See also that you didn't close a bracket.

A:

There are two problems. Firstly, you are missing a closing bracket at the end of your if condition, and secondly you have quotes where you should not, surrounding the call to htmlspecialchars. 
The correct code would be:
if (file_exists('pdf/'.htmlspecialchars($_POST['apt'], ENT_COMPAT).'.pdf')) {
    echo "the file exists";
}  else {
    echo "file does not exist";
}

