2014-09-10 134 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。