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
I need serious help
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: I need serious help
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
echo $_SERVER['DOCUMENT_ROOT'];
Its not working becz i am working out side docmentroot.
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
This shows that it thinks the name of the directory contains a cr/lf.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
Add a $var = trim($var) statement to get rid of it.
Re: I need serious help
Remove the document root and try again.
if that doesn't work then try giving full path
Example: root/etc/
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
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.
$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.