开发者

How to parse a JPG as PHP and return a JPG

I have a dynamic image I'm trying to create, which previously worked on one web host, until I found out they removed some features, some of which broke my image. I recently moved to hostgator, and I can't get the image to work on their site either. The actual PHP script isn't important, as I am entirely sure it works, because when I go to /image.php it displays the image, but when I go to /image.jpg it does not.

What I am trying to do here is, have PHP code inside a file with a JPG extension, which is what I have at /image.jpg, not an actual image, but PHP code. I need the server to parse the JPG as PHP code, but return a JPG so that I can use the image in places that only allow images with image extensions, such as forums. The forum I am on will not accept the image with the PHP extension, that's why I need this to work as described.

The only thing I have found and tried was putting this in .htaccess:

<Files image.jpg>
ForceType application/x-httpd-php
</Files>

The .htaccess file is in the same directory as the image, and this method also used to work, but not anymore. I've tested the image as PHP with hostgator and it works fine, I just need a way to use /image.jpg properly again.

In case it helps, what my PHP script does is开发者_如何转开发, takes a background image, uses ImageTTFText to alter it with things such as, a view count, an IP address display, and a few other things. As I said, the script itself works, I tested it on hostgator already, but I need to be able to put the script inside the JPG file, and have it so that when someone views the JPG, it displays the image as it's supposed to.

Any help is greatly appreciated, thank you.

EDIT: The Rewrite trick in .htaccess didn't work either. It redirects image.jpg to image.php, and the forum still won't let me use the image. Also, as for Apache's config files, I'm pretty sure I have access to that. I'm not very experienced with this, but in the cPanel I have access to Apache Handlers, which says it lets me control how the web server handles certain file types. I just don't know what to enter here for it to work as I need it, but I think it may be what I need. If anyone knows if this would help, or how to use it, please give some advice. Thank you.

EDIT: I don't know if this is what you mean, but here are the image creation parts of the script:

Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

$image = imagecreatefromjpeg("background.jpg");

$img_width = 514;
$img_height = 128;

imagepng($image);
imagedestroy($image);


You can try something like

RewriteEngine on
RewriteRule image.jpg image.php [R=301]

edited to add:

In case you didn't know, you put this in your .htaccess file. With the proper path/to/file of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜