php 执行系统命令的方法
时间:2020-12-20 12:34:51|栏目:PHP代码|点击: 次
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
int main(int argc,char * argv[])
{
uid_t uid,euid;
char cmd[1024]="chmod -R 777 ";
uid =getuid();
euid = geteuid();
//printf("param %s\n",strcat(cmd,argv[1]));
//exit(0);
//printf("uid:%un. eudi=%un\n",getuid(),geteuid());
if(setreuid(euid,uid))
perror("setreuid");
//printf("uid:%un. eudi=%un\n",getuid(),geteuid());
system(strcat(cmd,argv[1]));
return 0;
}
现在说下,在linux下面,gcc编译,以及复权的问题:
执行
gcc -Wall -o phpchmod phpchmod.c
执行
chmod u+s ./phpchmod
php代码的使用:
$chmod_line = dirname(__FILE__)."/phpchmod ./dest_dir/";
system($chmod_line);
复制代码 代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
int main(int argc,char * argv[])
{
uid_t uid,euid;
char cmd[1024]="chmod -R 777 ";
uid =getuid();
euid = geteuid();
//printf("param %s\n",strcat(cmd,argv[1]));
//exit(0);
//printf("uid:%un. eudi=%un\n",getuid(),geteuid());
if(setreuid(euid,uid))
perror("setreuid");
//printf("uid:%un. eudi=%un\n",getuid(),geteuid());
system(strcat(cmd,argv[1]));
return 0;
}
现在说下,在linux下面,gcc编译,以及复权的问题:
执行
gcc -Wall -o phpchmod phpchmod.c
执行
chmod u+s ./phpchmod
php代码的使用:
复制代码 代码如下:
$chmod_line = dirname(__FILE__)."/phpchmod ./dest_dir/";
system($chmod_line);