下载PHP脚本而不是执行它 [英] Download PHP script instead of executing it
问题描述
我在网站上有一个downloads
目录,我在其中存储了一堆不同的文件供人们下载(zip,exe,java,php等).问题是我的网站是用PHP编写的,因此Web服务器Apache尝试执行脚本,而不是让人们下载脚本.没有访问Apache配置的权限(我在共享主机上),阻止Apache在单个目录中执行脚本的最简单方法是什么?
I have a downloads
directory on a website where I store a bunch of different files for people to download (zip, exe, java, php, etc). The problem is that my website is written in PHP, so the web server, Apache, tries to execute the scripts instead of letting people download them. Without having access to Apache config (I'm on shared hosting), what is the easiest way to prevent Apache from executing scripts in a single directory?
我尝试未成功使用 mod_mime . AddType不起作用,因为(我猜)MIME类型已经与PHP脚本关联. ForceType不起作用,因为我在目录中存储了不同类型的文件.还有其他选择吗?
I tried using mod_mime unsuccessfully. AddType doesn't work because (I'm guessing) a MIME type is already associated with PHP scripts. ForceType doesn't work because I store different types of files in the directory. Are there any other options?
推荐答案
如果您具有足够的权限,请将以下行放在您不想执行PHP脚本的目录中的.htaccess
文件中可能会解决问题:
If you have sufficient permissions for that, putting the following line in a .htaccess
file in the directory in which you don't want PHP script to be executed might do the trick :
php_flag engine off
(只需在我的网络服务器上进行测试,我就获得了PHP脚本的源代码-尚未执行)
这篇关于下载PHP脚本而不是执行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!