Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Checks whether we may call gs through exec().
- *
- * @return bool|str If available, returns exe path. False otherwise.
- */
- private static function getGhostscriptExecutable() {
- static $executable = null;
- if (is_null($executable)) {
- // we must be able to exec()
- $executable = self::isExecAvailable();
- if (!$executable) return $executable;
- // find on Windows system
- if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
- // look for environment variable
- $executable = getenv('GSC');
- if($executable) return $executable;
- // hope GS in the path
- $executable = exec('where gswin*c.exe');
- if(!empty($executable)) return $executable;
- // look directly in filesystem
- // 64- or 32-bit binary
- $executable = exec('dir /o:n/s/b "C:\Program Files\gs\*gswin*c.exe"');
- if (!empty($executable)) {
- return $executable;
- }
- // 32-bit binary on 64-bit OS
- $executable = exec('dir /o:n/s/b "C:\Program Files (x86)\gs\*gswin32c.exe"');
- $executable = empty($executable) ? false : $executable;
- return $executable;
- }
- // this is why I use Linux...
- $executable = exec('which gs');
- $executable = empty($executable) ? false : $executable;
- return $executable;
- }
- return $executable;
- }
- /**
- * Checks whether exec() may be used.
- * Source: http://stackoverflow.com/a/12980534/866618
- *
- * @return bool Whether exec() is available.
- */
- private static function isExecAvailable() {
- static $available = null;
- if (is_null($available)) {
- $available = true;
- if (ini_get('safe_mode')) {
- $available = false;
- } else {
- $d = ini_get('disable_functions');
- $s = ini_get('suhosin.executor.func.blacklist');
- if ("$d$s") {
- $array = preg_split('/,\s*/', "$d,$s");
- if (in_array('exec', $array)) {
- $available = false;
- }
- }
- }
- }
- return $available;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement