「PHP入門」Linixの外部コマンドexec(),system(),passthru()を実行する

1.exec()
<?php
exec(“dir”,$output);
print_r($output);
?>

2.system()
<?php
system(“pwd”,$result);
print $result;
?>

3.passthru()
<?php
header(“Content-type:image/gif”);
passthru(“/usr/bin/ppm2tiff /usr/share/tk8.4/demos/images/teapot.ppm”);
?>

4.shell_exec()
<?php
$output = shell_exec(‘ls -lart’);
echo “<pre>$output</pre>”;
?>

5.popen()
<?php
error_reporting(E_ALL);
$handle = popen(‘/path/to/executable 2>&1’, ‘r’);
echo “‘$handle’; ” . gettype($handle) . “\n”;
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>

Comments are closed.