1

I'm sure I'm missing something obvious here. I want to include a php file but I need to check if it exists first and every time I run it, I get a failure message. I can see the file is there from my FTP application.

        <?
            $man_file="/site/67/blog/612.php";
            if (file_exists($man_file)){
                include($man_file);
            }
            else
            {
                echo $man_file;
            }
            clearstatcache();
        ?>

Am I missing something?

21
  • 3
    What failure message are you getting? Commented Sep 22, 2016 at 15:34
  • 1
    failure message you say? Commented Sep 22, 2016 at 15:34
  • 2
    Add a echo getcwd(); just to prove PHP is looking in the directory you think it is Commented Sep 22, 2016 at 15:42
  • 2
    $man_file="/site/67/blog/612.php"; use a full server path $man_file="/var/usr/public/site/67/blog/612.php"; or a relative one. You have been asked what error you get back, the "real" one and on more than one occasion. I can't keep guessing what that is; "file not found"? Other? Commented Sep 22, 2016 at 15:48
  • 1
    That did it Fred. I've never had to do that before. Post it as an answer and I'll upvote it and accept it. Commented Sep 22, 2016 at 15:50

2 Answers 2

1

That did it Fred. I've never had to do that before. Post it as an answer and I'll upvote it and accept it. – Richard Young

Posting my comment as "the" answer:

$man_file="/site/67/blog/612.php";

Use a full server path (an example):

$man_file="/var/usr/public/site/67/blog/612.php"; 

or a relative one.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to put the path to the file as well. So try something like

$man_file=$_SERVER['DOCUMENT_ROOT']."/612.php";

If the directory you are searching is the root.

1 Comment

I tried including the path. I tried the full path it tired putting "./" before it but nothing made any difference.

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.