Linux system command php method to execute system command

WBOY
Release: 2016-07-29 08:40:20
Original
1204 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template