php 执行系统命令的方法

yipeiwu_com6年前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);

相关文章

数组与类使用PHP的可变变量名需要的注意的问题

有时候可变的变量名会给编程带来很大的方便。也就是说变量名可以被动态的命名和使用。通常变量通过下面这样的语句来命名 :$a = 'hello';可变变量名指的是使用一个变量的值作为这个变量...

GBK的页面输出JSON格式的php函数

复制代码 代码如下:function tb_json_encode($value, $options = 0) { return json_encode(tb_json_convert_...

php number_format() 函数通过千位分组来格式化数字的实现代码

定义和用法number_format() 函数通过千位分组来格式化数字。 语法number_format(number,decimals,decimalpoint,separator)...

php递归实现无限分类的方法

本文实例讲述了php递归实现无限分类的方法。分享给大家供大家参考。具体如下: <?php $rows = array( array( 'id' =>...