I am trying to see if a directory exists, but have not found anything that is working the way is I would like it to.
The PHP script is in the same directory as the folders I am checking for ( www ), but will not detect the folders unless I type out the full path.
(( I apologize for clumping the code together to save space ))

<html>
<title>Test Server</title>
<?php
$Var1 = "\Player\Rick"; $Var2="C:\wamp\www\Player\Rick";
# This Will Not Work
if ( is_dir($Var1) ){echo "Yes 1 <br>" ;}
else{echo "No 1 <br>";}
# This Will Work
if ( is_dir($Var2) ){echo "Yes 2 <br>" ;}
else{echo "No 2 <br>";}
?>
</html>
Member Avatar for diafol

When using many file functions in php, the '\' or '/' will go to webroot - so in your case '\Player\Rick' is probably looking for 'c:\Player\Rick'.

Take off the original '\'. You may find a forward slash better, as backslashes have a nasty habit of escaping certain characters (or creating newlines etc) when placed within "double quotes".

$Var1 = "Player/Rick"; //if this is current directory

$Var1 = "../Player/Rick"; // if 'Player' is in parent directory 

Thank you for the reply. Using "Player/Rick" doesn't seem to do anything. I have been playing around with it, and found the following works the best. Is there a better way to do it ?

    <html>
    <title>Test Server</title>
    <?php
    $Var1 = ".\\Player\\Rick";
    if ( is_dir($Var1) && file_exists($Var1 . "\\Blarg.txt") ){
    echo "Yes  <br>" ;
    }
    else{
    echo "No  <br>";
    }
    ?>
    </html>
Member Avatar for diafol
$Var1 = "./player/rick";
if ( is_dir($Var1) && file_exists($Var1 . "/blarg.txt") ){
echo "Yes  <br>" ;
}
else{
echo "No  <br>";
}

Should work for you.
The previous example I gave works for me. Can't say why it doesn't for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.