欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP中執(zhí)行cmd命令的方法

 更新時(shí)間:2014年10月11日 00:10:30   投稿:mdxy-dxy  
這篇文章主要介紹了PHP中執(zhí)行cmd命令的方法,需要的朋友可以參考下

本文介紹下,在php代碼中執(zhí)行cmd命令的方法,介紹下在php.ini文件中配置safe_mode參數(shù)支持命令執(zhí)行的方法,有需要的朋友參考下。

說(shuō)明:
本節(jié)內(nèi)容在wamp包安裝的環(huán)境實(shí)現(xiàn)。

首先,打開(kāi)php.ini,關(guān)掉安全模式safe_mode = off,然后在看看 禁用函數(shù)列表 disable_functions = proc_open, popen, exec, system, shell_exec ,把exec去掉。
php代碼:

復(fù)制代碼 代碼如下:

<?php
exec("mkdir d:\\test",$out);
print_r($out);
?>

執(zhí)行該php文件,會(huì)發(fā)現(xiàn)在d盤(pán)下多了一個(gè)test文件夾。

參考文檔:

exec函數(shù)解析
exec語(yǔ)法: string exec(string command, string [array], int [return_var]);
exec返回值: 字符串

exec參數(shù)說(shuō)明
Command – 需要執(zhí)行的命令
Array –  是輸出值
return_var –是返回值0或1,如果返回0則執(zhí)行成功,返回1則執(zhí)行失敗。
exec不成功,調(diào)試方案

技巧分享:

使用管道命令, 使用 2>&1, 命令就會(huì)輸出shell執(zhí)行時(shí)的錯(cuò)誤到$output變量, 輸出該變量即可分析。

例如:

exec(‘convert a.jpg b.jpg', $output, $return_val);
修改為:

復(fù)制代碼 代碼如下:

exec(‘convert a.jpg b.jpg 2>&1′, $output, $return_val);
print_r($output);

相關(guān)文章

最新評(píng)論