0

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>
2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by diafol
0

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 

Edited by diafol

0

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>
0
$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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.