如何以纯文本格式在网络服务器上发布php文件
I want to post all of my source code for a project on my webserver however I have a problem. All of the source code is in php and when I post it the server tries to execute it.
To try and avoid this I changed the file extension to .html however this did not work. When I post java files they just show up in plain text is there somehow that I can post php files like this?
我想在我的网络服务器上发布项目的所有源代码但是我遇到了问题。 所有源代码都在php中,当我发布它时,服务器会尝试执行它。 p>
为了避免这种情况,我将文件扩展名更改为.html但是这不起作用。 当我发布java文件时,他们只是以纯文本显示是否有某种方式我可以发布像这样的PHP文件? p> div>
Change the extension to .txt?
If you're using apache, you can add a .htaccess file in your source directory that contains:
AddType text/plain .php
Alternatively, you can try using the .phps
extension if your server is set up for that.
If you are using Apache and mod_php there should be a line in your httpd.conf file with something like:
AddType application/x-httpd-php .php5 .php4 .php
Make sure .html isn't in this list.
use .htaccess directives. unset the php handler and put .htaccess into the directory you want php scripts deny executing
the .phps
(php source) extension is supported by some servers and will even do source highlighting for you.
You might have to do a AddType application/x-httpd-php-source .phps
in the .htaccess file to get this to work properly though.
If the .phps
extension is not supported by your server you can roll your own.
In .htaccess:
AddType application/x-httpd-php-source .phps
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} \.phps$
RewriteRule ^(.*)s$ source.php?file=$1
</IfModule>
And accompanying source.php
file:
// Basic filename sanitization
$file = './' . preg_replace("/[^a-zA-Z0-9\/\.-_]/", '', $_GET['file']);
if (file_exists($file)) {
highlight_file($file);
}
You should run the source code through a code formatter to generate pretty HTML files and publish that as separate HTML documents.