下载PHP脚本而不是执行它 [英] Download PHP script instead of executing it

查看:72
本文介绍了下载PHP脚本而不是执行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆