加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何将上传的php文件显示为纯文本而不是在wordpress中执行?

发布时间:2020-12-13 13:17:08 所属栏目:PHP教程 来源:网络整理
导读:编辑/ tmp中的testme.php文件. ?phpecho "test";? 编辑一篇名为test and upload file /tmp/testme.php的新帖子,用url http://home.local/wp/?p = 4785发布. 我想看看testme中的内容,点击它,在wordpress中弹出新窗口. 继续点击它.网页上显示的测试结果. 我
编辑/ tmp中的testme.php文件.
<?php
echo  "test";
?>

编辑一篇名为test and upload file /tmp/testme.php的新帖子,用url http://home.local/wp/?p = 4785发布.

我想看看testme中的内容,点击它,在wordpress中弹出新窗口.

继续点击它.网页上显示的测试结果.

我的期望:
1.只需在测试帖中点击testme一次.
2.将testme.php显示为纯文本,

<?php
echo  "test";
?>

而不是执行testme.php的结果.

test

我根据一些材料显示配置php文件作为apache中的纯文本.

sudo vim /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    ServerName www.home.local
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
        <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            allow from all
            php_flag engine off
            AddType text/plain php
        </Directory>
</VirtualHost>

重启apache2(在debian中构建).

sudo systemctl restart apache2

要打开帖子http://home.local/wp/?p = 4785,我在网页上得到以下输出:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything,but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES',true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
您已经拥有了正确的代码 – AddType text / plain php,这将使Apache将PHP文件(或名称以.php结尾的文件)视为纯文本文件.

但假设如下:

>您在/ var / www / html目录中安装了WordPress.
> PHP文件上传到WordPress中的默认上传文件夹(wp-content / uploads).

如果将目录设置为/ var / www / html / wp-content / uploads,如下所示:

<Directory /var/www/html/wp-content/uploads>
  AddType text/plain php
</Directory>

你会得到你想要的结果 – 只有uploads文件夹中的PHP文件将被视为纯文本文件,而不是/ var / www / html目录中的所有PHP文件.这解释了“要打开帖子http://home.local/wp/?p = 4785,我得到以下输出”的问题,其中输出是文件/ var / www / html / index中的代码. PHP.我的意思是,你使用< Directory / var / www / html>,这使得Apache将index.php文件视为纯文本文件,而不是在文件中执行PHP代码.

备用方法:使用.htaccess文件.

特别是如果您无法编辑或无法访问Apache的配置(.conf)文件.

>在uploads文件夹中创建.htaccess,如果它还没有.
>然后在该文件中添加AddType text / plain php.

补充说明

I want to see the content in testme.php,click it,pop up new window

我确信你可以做到这一点或者已经拥有代码/解决方案,但是一个简单的方法,就是将target =“_ blank”添加到附件/文件链接..或者使用JavaScript,你可以使用window.open().

并且您必须采取全面的安全措施,因为允许人们上传PHP文件可能会损害您的网站和/或您的网站用户.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读