5
<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
}
?>

That script only checks if a file exists, but how do I do something like this?

<?php
$filename = '/path/to/foo.txt';

if (file doesnt exist) {
    exit("Your file doesn't exist");
}
?>
2
  • 9
    if (!file_exists($filename)) { Commented Feb 25, 2015 at 0:11
  • 1
    Thanks, I'm sorry for the stupid question, please bear with me I'm still learning.... Commented Feb 25, 2015 at 0:14

2 Answers 2

20

As John Conde said, you should negate the file_exists function:

if (!file_exists($filename)) {
    exit("Your file doesn't exist");
}
Sign up to request clarification or add additional context in comments.

Comments

0

becarefull if you are using CODEIGNITER, dont use base_url() inside file path, use normal path

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.