This article describes, in the PHP code to execute the CMD command method, introduced in the php.ini file to configure Safe_mode parameters to support the implementation of the command method, the need for a friend reference.
Description
The contents of this section are implemented in the context of the WAMP package installation.
First, turn on the php.ini, turn off safe mode Safe_mode = off, and then look at the disabled function List disable_functions = Proc_open, Popen, exec, System, shell_exec, remove exec.
PHP Code:
Copy Code code as follows:
<?php
EXEC ("mkdir d:\\test", $out);
Print_r ($out);
?>
If you execute the PHP file, you will find a test folder on the D disk.
Reference Documentation:
exec function parsing
EXEC syntax: string exec (String command, string [array], int [return_var]);
EXEC return Value: string
EXEC parameter description
command– the command to be executed
array– is the output value
return_var– is the return value of 0 or 1, and if 0 is returned, the execution succeeds, and the return 1 fails.
exec unsuccessful, debug scenario
Skill Sharing:
Using the pipe command, using 2>&1, the command will output the error from the shell execution to the $output variable, and the variable can be parsed.
For example:
EXEC (' Convert a.jpg b.jpg ', $output, $return _val);
Modified to:
Copy Code code as follows:
EXEC (' Convert a.jpg b.jpg 2>&1′, $output, $return _val);
Print_r ($output);