shell_exec() will not execute outside htdocs folder

Problems with the Windows version of XAMPP, questions, comments, and anything related.

shell_exec() will not execute outside htdocs folder

Postby sundrop187 » 26. July 2010 07:41

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.
sundrop187
 
Posts: 4
Joined: 26. July 2010 07:20

Re: shell_exec() will not execute outside htdocs folder

Postby JonB » 26. July 2010 10:57

You answered your own question. READ carefully what you posted right down to the last statement.
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: shell_exec() will not execute outside htdocs folder

Postby sundrop187 » 28. July 2010 04:37

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!
sundrop187
 
Posts: 4
Joined: 26. July 2010 07:20

Re: shell_exec() will not execute outside htdocs folder

Postby sundrop187 » 28. July 2010 05:53

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:
sundrop187
 
Posts: 4
Joined: 26. July 2010 07:20

Re: shell_exec() will not execute outside htdocs folder

Postby JonB » 28. July 2010 13:38

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.

:!:
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: shell_exec() will not execute outside htdocs folder

Postby sundrop187 » 28. July 2010 23:01

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.
sundrop187
 
Posts: 4
Joined: 26. July 2010 07:20


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 135 guests