如何在png / jpg扩展名中运行php脚本 [英] How to run php script in png/jpg extension

查看:224
本文介绍了如何在png / jpg扩展名中运行php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编辑.htaccess文件以使客户端运行php脚本,但扩展名为png / jpg。如此...
用户将访问网址

How can i edit .htaccess file to make client run php script, but in png/jpg extension. Soo... User will visit url

http://example.com/script.png ,他将看到测试(PHP脚本将返回此值),而不是图像。
那就是我已经做过的:
.htaccess文件:

http://example.com/script.png and he will see "test"(php script will return this value), not image. That's what i already did: .htaccess file:

AddType application/x-httpd-php .png

script.png文件:

script.png file:

<?php
header("Content-type: image/png");
echo 'test';
?>

此代码有什么问题?为什么不起作用?浏览器尝试下载图像:/

What is wrong with this code? Why it doesn't work? Browser tries to download the image :/

推荐答案

将以下行添加到您的 .htaccess 文件

Add the following line to your .htaccess file

AddHandler application/x-httpd-php .png

这告诉服务器将所有以 .png 结尾的文件处理为 .php

This tells the server to process all files ending with .png as .php.

这篇关于如何在png / jpg扩展名中运行php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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