[email protected]

Well-Known Member
Mar 5, 2002
487
0
316
Los Angeles California
Hi guys,

There must be something weird about the CPanel directory system.

I did the following script but it doesn't work.

I put a dir.php on the root of my Cpanel skin.
This script is supposed to output 'There is a mail folder' if it detects a folder with the name 'mail'
Obviously there is a folder 'mail' in the cpanel skin, but i got an error.

the code
<?
$handle = opendir(mail);

while($filename = readdir($handle))
{
if ($filename != "." && $filename != "..")
{
if(is_dir($filename))
print '<font color="#0033CC">There is a mail folder</font>';
}
}
?>


The error
Warning: OpenDir: No such file or directory (errno 2) in /tmp/cpanel.auto.1052482570.5401 on line 4

Warning: readdir(): supplied argument is not a valid Directory resource in /tmp/cpanel.auto.1052482570.5401 on line 6



What is wrong here?
Is there any solution to this?
 

Allowee

Registered
May 8, 2003
4
0
151
Originally posted by [email protected]

the code
<?
$handle = opendir(mail);

while($filename = readdir($handle))
{
if ($filename != "." && $filename != "..")
{
if(is_dir($filename))
print '<font color="#0033CC">There is a mail folder</font>';
}
}
?>
"$handle = opendir(mail);" is the problem...
try
"$handle = opendir("mail");" instead.
should work.
it that doesn't work becouse there is no 'mail' dir in /tmp you need to give the full path..
"$handle = opendir("/full path where you want to look/mail");"
 
Last edited:

[email protected]

Well-Known Member
Mar 5, 2002
487
0
316
Los Angeles California
Re: Re: Cpanel has weird behavior

Originally posted by Allowee
"$handle = opendir(mail);" is the problem...
try
"$handle = opendir("mail");" instead.
should work.
it that doesn't work becouse there is no 'mail' dir in /tmp you need to give the full path..
"$handle = opendir("/full path where you want to look/mail");"
I tried adding the " but it still doesnt work.
 

Allowee

Registered
May 8, 2003
4
0
151
thinking about it......
PHP:
<?php
if( @is_dir("mail") ){ 
 echo "There is a mail folder";
}
?>
you are looking in a dir. but if it doesn't have permissions to allow apache to look in it it will fail.
and look in a dir to see if it's there can be done with above code :)
it just checks if "mail" is a dir, if not it doesn't return a errors because there is a '@' in front of it
 

[email protected]

Well-Known Member
Mar 5, 2002
487
0
316
Los Angeles California
No good.:(

There is still error

Parse error: parse error in /tmp/cpanel.auto.1052493354.18381 on line 2
 

Allowee

Registered
May 8, 2003
4
0
151
do you have any idea what code is around line 2

i just checked on php.net...
it's not a new function so it should work...
but what i did saw was about an extra /

so "mail/" is how it should be...

but that won't get a parse error..
so i guess you need to post a bit (password free) code
 

[email protected]

Well-Known Member
Mar 5, 2002
487
0
316
Los Angeles California
the code is exactly the same as the one I gave you:

<?phpif( @is_dir("mail") ){ echo "There is a mail folder";}?>

But it doesnt work because of the weird way CPanel parses directory. Is there anyway around this?
Does anyone know where the MAIL folder is in the TMP folder?
 

Allowee

Registered
May 8, 2003
4
0
151
Originally posted by [email protected]
the code is exactly the same as the one I gave you:

<?phpif( @is_dir("mail") ){ echo "There is a mail folder";}?>

But it doesnt work because of the weird way CPanel parses directory. Is there anyway around this?
Does anyone know where the MAIL folder is in the TMP folder?
in your first post you said you wanted to look in the skin directory?
then it should be something like
<?php
if( @is_dir("/usr/local/cpanel/base/frontend/skin_name/mail/") ){
echo "There is a mail folder";
}
?>
and if that still doesn't wrk you can try putting a chdir("/blah"); before the if()

i haven't looked how to 'rip' the users skin.. it should be somewhere so change the cofde for that.
and if it still doesn't work you should post the full warnings/parse errors.

btw, is that the only php you use in that file? it could be that '<?php' is already used. so you can also try to remove '<?php' and '?>'

good luck :)