2014-09-10 132 views
0

我尝试从PHP运行java,但我甚至无法使用java可执行文件的绝对路径(C:\ Windows \ System32 \ java.exe)。从PHP脚本运行java

我发现问题是PHP不能访问这个文件,出于某种原因。我尝试:

<?php var_dump(file_exists('C:\Windows\System32\java.exe')); // returns false. 

文件实际上存在,我(用户在谁我运行php脚本)有权限读取和执行它。 这是非常奇怪的,因为我可以执行的notepad.exe和

<?php var_dump(file_exists('C:\Windows\System32\notepad.exe')); // returns true. 

任何想法?

php -v 
PHP 5.3.27 (cli) (built: Jul 10 2013 20:36:59) 
Copyright (c) 1997-2013 The PHP Group 
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies 
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans 

java -version 
java version "1.7.0_40" 
Java(TM) SE Runtime Environment (build 1.7.0_40-b43) 
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode) 

操作系统Windows 7的64位

PHPINFO:

phpinfo()函数 PHP版本=> 27年3月5日

System => Windows NT IT8 6.1 build 7601 (Windows 7 Business Edition Service Pack 1) i586 
Build Date => Jul 10 2013 20:35:35 
Compiler => MSVC9 (Visual C++ 2008) 
Architecture => x86 
Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" 
Server API => Command Line Interface 
Virtual Directory Support => disabled 
Configuration File (php.ini) Path => C:\Windows 
Loaded Configuration File => C:\Program Files (x86)\PHP\php.ini 
Scan this dir for additional .ini files => (none) 
Additional .ini files parsed => (none) 
PHP API => 20090626 
PHP Extension => 20090626 
Zend Extension => 220090626 
Zend Extension Build => API220090626,NTS,VC9 
PHP Extension Build => API20090626,NTS,VC9 
Debug Build => no 
Thread Safety => disabled 
Zend Memory Manager => enabled 
Zend Multibyte Support => disabled 
IPv6 Support => enabled 
Registered PHP Streams => php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, https, ftps, phar, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp 
Registered Stream Socket Transports => tcp, udp, ssl, sslv3, sslv2, tls 
Registered Stream Filters => convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.* 

回答

0

作为一个建议:
从PHP.net到file_exists:

This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.

另外:
结果的file_exists将被缓存。
也许你要调用clearstatcache()

编辑
您可以尝试以下操作:

<?php var_dump(file_exists("C:\\Windows\\System32\\java.exe"));

+0

safe_mode在我的php.ini中被禁用 clearstatcache()没有帮助 – NikitaObukhov 2014-09-10 09:30:40

+0

我编辑了我的答案... – Ben 2014-09-10 09:37:58

0

遇到同样的问题,并从Windows/System32文件夹搬迁的java.exe 来解决问题例如C:/ Java (假设可执行文件C:/Java/java.exe现在实际存在)'file_exists(“C:/Java/java.exe”)'(和'is_executable(“C:/ Java/java。 exe“)') 现在应该返回true。