PHP系统命令函数使用分析

yipeiwu_com6年前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应用JSON技巧讲解

php json_decode返回数据js的处理 php json_decode后,返回到前台的数据如:encode_str =》{"green":10,"size":5,"strock...

mac 下安装php7全过程介绍

更新系统库 yum -y install gcc gcc-c++ automake autoconf libtool make lrzsz expect asciidoc xmlto...

PHP闭包实例解析

本文实例分析了PHP程序设计中闭包的概念机用法,分享给大家供大家参考。具体分析如下: 通常来说,闭包也就是PHP的匿名函数, 但是和函数不同的是,闭包可以通过use使用函数声明时所在作用...

php FPDF类库应用实现代码

复制代码 代码如下:<?php require('chinese.php'); class PDF extends PDF_Chinese { function Header()...

php 批量生成html,txt文件的实现代码

首先建立一个conn.php的文件用来链接数据库复制代码 代码如下:<?php    $link = mysql_connect("mysql_hos...