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将session信息存储到数据库的类实例

本文实例讲述了PHP将session信息存储到数据库的类。分享给大家供大家参考。具体分析如下: SessionHandlerInterface接口是PHP内置的接口,直接实现就行了 具体...

PHP去除空数组且数组键名重置的讲解

php空数组的话,能够运用 php函数array_filter() . array array_filter ( array [, callback callback] ) ar...

详解PHP中的mb_detect_encoding函数使用方法

php中可以使用 mb_detect_encoding() 函数来判断字符串是什么编码的。 当在php中使用mb_detect_encoding函数进行编码识别时,很多人都碰到过识别编码...

PHP类与对象中的private访问控制的疑问

复制代码 代码如下: class Bar { public function test() { $this->testPrivate(); $this->testPublic...

mac os快速切换多个PHP版本的方法

php是为了快速构建一个web页面而迅速被大家广为接受的开源语言,通过不断发展已经有了很多的php开源系统,满足了目前大部分用户的站点需求。1995年初php诞生到现在已经存在多个版本,...