简体   繁体   中英

Checking existence of file in same folder

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?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM