Page 1 of 1
I need serious help
Posted: Thu Sep 04, 2008 4:54 pm
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
Re: I need serious help
Posted: Thu Sep 04, 2008 5:08 pm
by Christopher
Re: I need serious help
Posted: Thu Sep 04, 2008 5:20 pm
by aliahsan81
echo $_SERVER['DOCUMENT_ROOT'];
Its not working becz i am working out side docmentroot.
Re: I need serious help
Posted: Thu Sep 04, 2008 8:58 pm
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.
Re: I need serious help
Posted: Fri Sep 05, 2008 12:45 am
by starram
Remove the document root and try again.
if that doesn't work then try giving full path
Example: root/etc/
Re: I need serious help
Posted: Fri Sep 05, 2008 4:54 am
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.