php 执行系统命令的方法

yipeiwu_com5年前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实现上传图片保存到数据库的方法

php实现上传图片保存到数据库的方法

php实现上传图片保存到数据库的方法。分享给大家供大家参考。具体分析如下: php 上传图片,一般都使用move_uploaded_file方法保存在服务器上。但如果一个网站有多台服务器...

php7安装openssl扩展方法

1、我的源码在 /home/topsec/Documents/php-7.0.11 ,安装位置在 /usr/local/php7, php.ini 在/ usr/local/php7/l...

php实现对文件压缩简单的方法

压缩一个文件 我们将一个文件生成一个压缩包。 <?php $path = "c:/wamp/www/log.txt"; $filename = "test.zip"...

php中 $$str 中 "$$" 的详解

这种写法称为可变变量 有时候使用可变变量名是很方便的。就是说,一个变量的变量名可以动态的设置和使用。一个普通的变量通过声明来设置,例如: <?php $a = "hel...

PHP Document 代码注释规范

1. 什么是phpDocumentor ? PHPDocumentor 是一个用PHP写的工具,对于有规范注释的php程序,它能够快速生成具有相互参照,索引等功能的API文档。老的版本是...