00001 <?php 00002 /* $Id: unix.php,v 1.3 2003/10/03 15:28:46 mikko Exp $ */ 00003 /* 00004 * ImaComm - a web based photo album software 00005 * Copyright (C) 2003, Mikko Kokkonen 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or (at 00010 * your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00020 */ 00035 function fs_find_executable($program) 00036 { 00037 return fs_int_exec("which", $program, 0); 00038 } 00039 00047 function fs_int_exec($program, $args, $return) 00048 { 00049 $cmd = "$program ".escapeshellcmd($args); 00050 // Can we use exec? 00051 if (function_exists("exec") && strstr(ini_get("disable_functions"), "exec") === false) 00052 { 00053 $none = exec($cmd, $output, $ret); 00054 // If command was successful... 00055 return implode("\n", $output); 00056 } 00057 // No exec, use popen... 00058 elseif (function_exists("popen") && strstr(ini_get("disable_function"), "popen") === false) 00059 { 00060 $fp = popen($cmd, "r"); 00061 while ($data = fread($fp, 2048)) 00062 { 00063 $buf .= $data; 00064 } 00065 pclose($fp); 00066 return $buf; 00067 } 00068 return ""; 00069 } 00070 ?>
1.3