Business has a need to do file operations, through PHP and Shell Interactive implementation
System (), Shell_exec () performs other systems such as Mv,cp,list, and PHP sets the appropriate security configuration to allow PHP system functions to operate, but it is not always successful when extracting a zip file.
Permissions are also changed to all permissions through A+w.
The commands I've tried are as follows
shell_exec("unzip " . BASE_PATH . "test/test.zip");//system('echo "密码" | sudo -S unzip ' . BASE_PATH . 'test/test.zip');system('echo "123456" | sudo -u root -S unzip ' . BASE_PATH . 'test/test.zip');system('echo "123456" | sudo -S unzip ' . BASE_PATH . 'test/test.zip');
The script is then accessed through the browser.
I ask you, is there any place you have not noticed?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The problem is resolved by changing the current working directory before executing shell_exec ().
chdir(BASE_PATH. "test/");
However, there are other problems, why the current PHP directory is base_path[my project root directory]?
Reply content:
Business has a need to do file operations, through PHP and Shell Interactive implementation
System (), Shell_exec () performs other systems such as Mv,cp,list, and PHP sets the appropriate security configuration to allow PHP system functions to operate, but it is not always successful when extracting a zip file.
Permissions are also changed to all permissions through A+w.
The commands I've tried are as follows
shell_exec("unzip " . BASE_PATH . "test/test.zip");//system('echo "密码" | sudo -S unzip ' . BASE_PATH . 'test/test.zip');system('echo "123456" | sudo -u root -S unzip ' . BASE_PATH . 'test/test.zip');system('echo "123456" | sudo -S unzip ' . BASE_PATH . 'test/test.zip');
The script is then accessed through the browser.
I ask you, is there any place you have not noticed?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The problem is resolved by changing the current working directory before executing shell_exec ().
chdir(BASE_PATH. "test/");
However, there are other problems, why the current PHP directory is base_path[my project root directory]?
This is PHP
the constant, ah, the system should not have BASE_PATH
this constant, it should be the framework you use or some of the files you contain define this constant. You can use get_defined_constants()
methods to get the constants that are already defined.
Why should we use chdir
it first?
Because unzip
this command by default is to extract the files into the current directory, rather than the directory of the zip file, so you need to know in which directory now, you can use system('pwd');
to view, and then see your Web users have no corresponding permissions to this directory, in theory, this directory should be you this PHP
the directory where the program is located, but if you are in use Cli
mode, that is your current directory, and where the PHP
program is irrelevant.
Of course, can not do chdir
, it requires you to unzip
have a corresponding understanding of the order, in fact, add a-d
You can put the extracted files into the specified directory.