php 只能在文档根目录下运行吗?
我在 Firefox Web 浏览器上使用 ubuntu 11.04 和 apache-mysql 服务器(我认为这称为 LAMP)。如果我将 php 文件放在文档根目录中,然后输入 http://localhost/myfile.php,它运行良好。但如果我只是单击它,它就会打开 Firefox 并提示我保存或下载文件。如果我把它放在桌面上,然后双击它,它就会执行保存或下载操作。这是为什么,我可以配置它,以便我可以像普通的 html 文件一样单击并显示吗?
I am using ubuntu 11.04 with an apache-mysql server (I think that is called LAMP) on a firefox web browser. If I put a php file in my document root, and then type http://localhost/myfile.php, it runs fine. But if I simply click it, it opens up firefox and prompts me to save or download the file. If I put it, say, on my desktop, and doubleclick it, it does the save or download thing. Why is this, and can I configure it so that I can just click and display like a normal html file would?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 是一种脚本语言。您从该地址看到的输出是执行的 PHP 文件生成的输出。当您双击它时,您(正确地)获得文件源。
PHP is a scripting language. The output you see from the address is the generated output of the executed PHP file. When you double click it you (correctly) get the file source.
PHP 文件在到达浏览器之前需要在服务器端进行解释。如果您只是使用 file:///foo/bar/myfile.php 打开它,Firefox 将不知道如何处理它,因为 Firefox 不解释 PHP。相反,Firefox 如何知道应该使用完全不相关的地址
http://localhost/myfile.php
打开/foo/bar/myfile.php
?底线:事实并非如此。
A PHP file needs to be interpreted server-side before it reaches the browser. If you just open it using
file:///foo/bar/myfile.php
, Firefox won't know what to do with it, because Firefox doesn't interpret PHP. Conversely, how would Firefox know that/foo/bar/myfile.php
should be opened using the completely unrelated addresshttp://localhost/myfile.php
?Bottom line: it just doesn't work that way.