在php中调用linux命令的函数是
string exec(string command,string[array],int[return_var]);
如:exec( "vpopmail ");echo exec('whoami');
再看一实例,代码如下:
function exec_enabled() { $disabled = explode(', ', ini_get('disable_functions')); return !in_array('exec', $disabled); }
<?php $tmp = exec("c:Imagegm.exe convert c:Imagefile1.tiff c:Imagefile1.jpg", $results); ?>
还有一种命令是:php通过函数system()调用系统命令.
string system ( string $command [, int &$return_var ] )
实例:system('asterisk -vvvvvvvvvvvc');
system()是一样的函数C的,它执行给定的命令和输出结果的版本,该system()的调用也尝试自动刷新网页服务器的输出缓冲器在每个输出行如果PHP运行作为服务器模块,如果你需要执行一个命令,并已全部通过直接从背面没有任何干扰的命令数据,使用passthru()函数.
$last_line = system('ls', $retval); function my_exec($cmd, $input='') { $proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], $input);fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } var_export(my_exec('echo -e $(</dev/stdin) | wc -l', 'hnelnlo'));
实例三,代码如下:
<?php $cmd = "date"; $output = system($cmd); printf("System Output: $output "); exec($cmd, $results); printf("Exec Output: {$results[0]} "); ?>
php调用linux命令的权限问题
你可以使用定时任务执行你要调用的php,这时的权限就是root,php通过函数system()调用系统命令.
php一般是以apache用户身份去执行的,把apache加入到存储你文件的父文件夹属组里去,然后改该父文件夹权限为775,这样属组成员就有写的权限,而apache属于这个组就可以改写该目录下所有文件的权限,当然,属组最好不要是root,你可以为该文件夹改个其它普通用户组.
改apache/php的运行用户方法不安全.
文章链接:
随便收藏,请保留本文地址!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function