![](/img/trans.png)
[英]How do I link JS external files outside of my PHP project root directory?
[英]How can I place a PHP script outside the root directory and link to it using HTML?
我正在使用wamp,並且有兩個目錄; / www和/ scripts。 在/ www中,我具有index.html,在/ scripts中,我具有test.php。 我不太熟悉標准的PHP目錄約定,但這是我希望在index.html文件中擁有的內容
...html statements...
<run the following php script: /scripts/test.php>
...html statements
而不是將PHP腳本本身包含在index.html文件中。
我在Apache(http://httpd.apache.org/docs/2.0/mod/mod_alias.html#scriptalias)中研究了ScriptAlias指令,但我不太了解如何將其應用於這種情況。 關於如何進行的任何想法?
您無法從HTML內部鏈接到文檔根目錄外部的PHP,但可以從PHP內部從文檔根目錄外部包含PHP。 即,將index.html替換為index.php,如下所示:
...html statements...
require_once '/path/to/scripts/test.php';
...html statements...
無法使用HTML完成,但是,如果您有一個index.php文件而不是index.html文件,則可以這樣做。 我想如果您必須將其保留為html文件,則可以設置apache將html編譯為php。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.