Home  >  Article  >  Backend Development  >  Linux system command php method to execute system command

Linux system command php method to execute system command

WBOY
WBOYOriginal
2016-07-29 08:40:201190browse

The code is as follows:

Copy the code The code is as follows:


#include
#include
#include
#include < unistd.h>
#include
int main(int argc,char * argv[])
{
 uid_t uid,euid;
 char cmd[1024]="chmod -R 777 ";
 uid =getuid();
euid = geteuid();
//printf("param %sn",strcat(cmd,argv[1]));
//exit(0);
//printf("uid: %un. eudi=%unn",getuid(),geteuid());
if(setreuid(euid,uid))
perror("setreuid");
//printf("uid:%un. eudi=% unn",getuid(),geteuid());
system(strcat(cmd,argv[1]));
return 0;
}


Now let’s talk about gcc compilation and restoration of rights under Linux :
Execute
gcc -Wall -o phpchmod phpchmod.c
Execute
chmod u+s ./phpchmod
Usage of php code:

Copy code The code is as follows:


$chmod_line = dirname(__FILE__) ."/phpchmod ./dest_dir/";
system($chmod_line);

The above introduces the Linux system command PHP method of executing system commands, including the content of Linux system commands. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn