PHP系统命令函数使用分析

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

function execute($cmd) {
     $res = '';
     if ($cmd) {
         if(function_exists('system')) {
             @ob_start();
             @system($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('passthru')) {
             @ob_start();
             @passthru($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('shell_exec')) {
             $res = @shell_exec($cmd);
         } elseif(function_exists('exec')) {
             @exec($cmd,$res);
             $res = join(“\n",$res);
         } elseif(@is_resource($f = @popen($cmd,"r"))) {
             $res = '';
             while(!@feof($f)) {
                 $res .= @fread($f,1024);
             }
             @pclose($f);
         }
     }
     return $res;
 }

相关文章

PHP文件锁定写入实例解析

本文以实例讲述了PHP文件写入方法,以应对多线程写入,具体代码如下: function file_write($file_name, $text, $mode='a', $timeo...

PHP中函数gzuncompress无法使用的解决方法

前言 gzuncompress函数不是php自带的系统函数而是一个插件函数了所以要使用 gzuncompress函数我们必须安装一个插件,下面来看看PHP函数gzuncompress无法...

php生出随机字符串

本文实例为大家分享了php生出随机字符串的具体代码,供大家参考,具体内容如下 function generateRandomString($length = 10) { $ch...

php 三大特点:封装,继承,多态

一.封装 目的:让类更安全 做法:成员变量变为私有的,通过方法间接操作成员变量,在方法里面加限制条件 二.继承 概念:子类可以继承父类的一切 方法重写:在子类里面对父类进行方法重写 特点...

JSON字符串传到后台PHP处理问题的解决方法

在项目开发的时候由于涉及到批量记录数组的传入,由于字段多,所以不可能能用普通的方式&a=322&=gsd&v=rwe 这样去传送,所以想到了前端传JSON格式过去content=[{'a...