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!
There are two problems. Firstly, you are missing a closing bracket at the end of your
ifcondition, and secondly you have quotes where you should not, surrounding the call tohtmlspecialchars.The correct code would be: