Page 1 of 1

shell_exec() will not execute outside htdocs folder

PostPosted: 26. July 2010 07:41
by sundrop187
I am trying to run Image Magick from shell_exec. I thought that would be more simple than trying to change the php version and compile Image Magick. Regardless of that, I seem to have a problem. Here it is.

Code: Select all
<?php

// shell_exec test
shell_exec('mkdir test');

//resulting output is found in
// C:/xampp/htdocs
//as the following:
// C:/xampp/htdocs/test

?>


That is expected. Here is the problem.

Code: Select all
<?php

$cmd1 = 'cd C:/';
$cmd2 = 'mkdir test2';

// shell_exec test 1
shell_exec($cmd1 && $cmd2);

//shell_exec test 2
shell_exec($cmd1."".$cmd2);

//shell_exec test 3
shell_exec('cd C:/; mkdir test2');


//resulting output is found in
// C:/
//as the following:
// C:/test2

?>


I have not found any result that works. I can:

Code: Select all
$output = shell_exec('dir');
echo $output;


I can't

Code: Select all
$output = shell_exec('chdir C:/')
//output in apache error log says "The system cannot find the path specified."


Any ideas?

PHP is not in safe mode.

Re: shell_exec() will not execute outside htdocs folder

PostPosted: 26. July 2010 10:57
by JonB
You answered your own question. READ carefully what you posted right down to the last statement.

Re: shell_exec() will not execute outside htdocs folder

PostPosted: 28. July 2010 04:37
by sundrop187
I put php in safe mode and tried to configure it to run exe's in a folder then some other stuff i found on forums but no luck. If you meant something specific about the settings maybe you can fill me in. I have no clue. most of the time the scripts i make are pretty simple. This is my first interface attempt. I have made some user input stuff, but right now the most fundamental thing has everything on hold. I have never had to do server stuff before. :lol: . Thanks for your help!

Re: shell_exec() will not execute outside htdocs folder

PostPosted: 28. July 2010 05:53
by sundrop187
Whoa! I think I have totally misguided you my friend. My question and explanation were rather vague even though I enclosed examples.

My file structure is:
C:-
Xampp-
htdocs-
php_file
I want to access:
C:-
Xampp-
Imagemagic-
convert.exe
I know that php will not "generate" outside of the htdocs folder as that is apache structure. I can run shell cmd's through the xampp control panel but not through the php shell_exec() function. This is what i am trying to accomplish. I can -"dir"- by itself and get the "htdocs" listing. I can't -"dir C:/"- and get its contents. This is through php. Shell through xampp control ... works perfectly. I actually tried the command line versions of a sample code in Linux and Windows xampp shell access and it all works but when I apply it in php nothing happens and apache logs reads "The system path cannot be found". Maybe that is what you thought I was trying to run php outside the htdocs folder. Maybe? :roll:

Re: shell_exec() will not execute outside htdocs folder

PostPosted: 28. July 2010 13:38
by JonB
right again --

Maybe that is what you thought I was trying to run php outside the htdocs folder. Maybe


because it (the shell command) is executing inside PHP, it is bound by the constraints of the server container. PHP on XAMPP is an Apache module. Thus - the script (in each instance) has no rights outside the defined bounds of the current DocumentRoot. You are getting file/path not found problems because of the scope of the server instance.

think of this -- Would you want a script on a shared Webhost to be able to modify the mounted filesystems outside of that users domain ????? :shock:

Noooo, huh?

Thus spake Zarathustra :idea:

any objects (tools or files) you wish to use will have to be inside your server's scope. try to think of it as if you were working remotely on someone else's server.

:!:

Re: shell_exec() will not execute outside htdocs folder

PostPosted: 28. July 2010 23:01
by sundrop187
Thanks. I had never had any server experience. This is my first time. I really appreciate your help. I understand this now. All my other suff runs on my webhost fine.