system() mangles the command in php
I'm trying to execute a command through system() in PHP. The command is /usr/bin/unzip, but the function returns with the error code 127开发者_开发问答. There is nothing else outputted. If I run the very same command directly in a shell it works.
The apache error log says 'sh: /unzip: not found'. I have also tried to put the command into a shell script that is in the same directory as the PHP script and call the shell script through system(). The same happens: if the shell script was called 'doit.sh' the error message in the apache log would be 'sh: /doit.sh: not found'.
exec() has the same behaviour.
The PHP version is 5.2.11-2 with suhosin extensions.
Any ideas what PHP could be doing to my command?
Rather than shelling out to unzip things, you could just use PHP's zip functions.
It looks as if you are sending the command 'unzip' when you should be using '/usr/bin/unzip'
If not, then, have you checked if your webserver runs in a chroot environment?
C.
Maybe try just with command name ?
system('unzip somestuff', $retval);
Turn off safe mode in php.ini.
If safe mode is on and the safe_mode_exec_dir
property is empty you'll get exactly the same behaviour as described.
精彩评论