Friday, 21 September 2018

How to show uploaded php file as plain text instead of executing it in wordpress?

Edit a testme.php file in /tmp.

<?php
echo  "test";
?>

Edit a new post titled test and upload file /tmp/testme.php ,pubish it with url http://home.local/wp/?p=4785.
enter image description here

I want to see the content in testme,click it,pop up new window in wordpress. enter image description here

Go on to click it.test shown in webpage.

My expect :
1.just click testme in test post for one time.
2.show the testme.php as plain text ,

<?php
echo  "test";
?>

instead of the result of executing testme.php.

test

I make a configuration according some material show php file as plain text in 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>

Reboot apache2(build in debian).

sudo systemctl restart apache2

To open the post http://home.local/wp/?p=4785,i got the following output in webpage:

<?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' );



from How to show uploaded php file as plain text instead of executing it in wordpress?

No comments:

Post a Comment