I need serious help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aliahsan81
Forum Newbie
Posts: 8
Joined: Thu Sep 04, 2008 4:46 pm

I need serious help

Post by aliahsan81 »

i making script for apache world writeable dir in php.my problem is want to get documenroot form httpd.conf,i m using shell_exce() function to run linux grep command to get documentroot now when i pass this variable i got this error i paste my code below plz ans asap.if u have any good idea or code will certainly help.

<?php
$var=shell_exec('grep ^DocumentRoot /etc/httpd/conf/httpd.conf|cut -d" " -f2| uniq' );
echo $var;
$all_dirs = scandir("$var");
echo $all_dirs;
?>
Output

"/var/www/html"
PHP Warning: scandir("/var/www/html"
): failed to open dir: No such file or directory in /root/scripts/file.php on line 8
PHP Warning: scandir(): (errno 2): No such file or directory in /root/scripts/file.php on line 8
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: I need serious help

Post by Christopher »

Wouldn't this be easier?

Code: Select all

echo $_SERVER['DOCUMENT_ROOT'];
(#10850)
aliahsan81
Forum Newbie
Posts: 8
Joined: Thu Sep 04, 2008 4:46 pm

Re: I need serious help

Post by aliahsan81 »

echo $_SERVER['DOCUMENT_ROOT'];

Its not working becz i am working out side docmentroot.
paperplate
Forum Newbie
Posts: 16
Joined: Thu Sep 04, 2008 12:15 pm

Re: I need serious help

Post by paperplate »

aliahsan81 wrote: PHP Warning: scandir("/var/www/html"
)
: failed to open dir: No such file or directory in /root/scripts/file.php on line 8
PHP Warning: scandir(): (errno 2): No such file or directory in /root/scripts/file.php on line 8
This shows that it thinks the name of the directory contains a cr/lf.

Add a $var = trim($var) statement to get rid of it.
User avatar
starram
Forum Commoner
Posts: 58
Joined: Thu Apr 10, 2008 1:27 am
Location: India
Contact:

Re: I need serious help

Post by starram »

Remove the document root and try again.

if that doesn't work then try giving full path

Example: root/etc/
aliahsan81
Forum Newbie
Posts: 8
Joined: Thu Sep 04, 2008 4:46 pm

Re: I need serious help

Post by aliahsan81 »

Thx alot that work trim function,what i did so if anyone need in future is this

$var=shell_exec('grep ^DocumentRoot /etc/httpd/conf/httpd.conf|cut -d" " -f2| uniq');
$var=str_replace('"', "", $var);
$var = trim($var);
$root_dir_path = $var;

Just one last problem working is now fine output looks great

a warning

PHP Warning: readdir(): supplied argument is not a valid Directory resource in /home/syed/write.php on line 141
/var/www/html/


Array
(
[0] => HTTP__/var/www/html/phpBB3/cache/.htaccess
[1] => HTTP__/var/www/html/phpBB3/cache/ctpl_admin_install_footer.html.php
[2] => HTTP__/var/www/html/phpBB3/cache/ctpl_admin_install_header.html.php
}

Any idea why still i have warning.
Post Reply