問題描述
可能的重復:
php 我該怎么做啟動一個外部程序運行 - 系統和執行有問題
如何用php打開exe?
我有這個想法并努力成功了好幾年,但最終失敗了.有人告訴我完成這項工作的成功方法嗎?
how to open exe with php?
I had this idea and make hard to success it for several years,but failed at last. any one tell me a success method to do the job ?
<?php
if(isset($_POST['file_path'])){
/* -------
using "notepad++.exe" to open "test.php" file.
or run a bat file which calling "notepad++.exe" to open "test.php" file.
how to seting php.ini or firefox or any setting to do this job.
it is only for conveniently developing web page in my PC ,not for web servers
------- */
}
?>
<form action="test.php" method="post">
<input type="text" name="file_path" value="test.php"/>
<button type="submit">open with notepad++</button>
</form>
這將創建類似:
推薦答案
在運行網絡服務器的計算機上啟動一個程序:
To launch a program on the computer which runs the webserver:
<?php
exec('"C:Program Files (x86)Notepad++
otepad++.exe" "C:foo.php"');
如果網絡服務器不作為 Windows 服務運行,上述內容將適用于 vista/win7.例如,如果您運行 apache 并且它會在您的計算機啟動時自動啟動,那么您可能將它安裝為一項服務.您可以檢查 apache 是否出現在 windows 服務選項卡/thingy 中.
The above will work on vista/win7 IF the webserver does not run as a windows service. For example, if you run apache and it automatically starts when your computer boots, you probably installed it as a service. You can check to see if apache shows up in the windows services tab/thingy.
如果網絡服務器作為服務運行,您需要考慮為該服務啟用允許桌面交互"選項.但除此之外:
If the webserver runs as a service, you'll need to look into enabling the "allow desktop interaction" option for the service. But otherwise:
使用 php 的新內置網絡服務器(php 5.4+)的簡單測試.這里的關鍵是您從 shell 手動啟動服務器,因此它作為您的用戶而不是作為服務運行.
An easy test using php's new built in webserver(php 5.4+). The key thing here is you manually start the server from a shell, so it runs as your user instead of as a service.
<?php
// C:myhtdocsscript.php
exec('"C:Program Files (x86)Notepad++
otepad++.exe" "C:foo.php"');
通過命令窗口啟動網絡服務器
start a webserver via a command window
C:path ophp.exe -S localhost:8000 -t C:myhtdocs
然后在您的瀏覽器中http://localhost:8000/script.php
這篇關于如何使用 PHP 啟動 Windows GUI 程序?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!