指向< img>标记到由PHP动态生成的图像? [英] Point an <img> tag to a image dynamically generated by PHP?

查看:76
本文介绍了指向< img>标记到由PHP动态生成的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将图像重定向到动态生成的图像(使用PHP)?

Is it possible to redirect an image to a dynamically generated image(using PHP)?

我有一个动态创建的映像,它的扩展名为".PHP"(显然),并且该服务器不受我的控制.所以我想将"somename.jpg"(在我的服务器上)重定向到"remoteserver/dynamicimage.php"(在不受我控制的某些远程服务器上),以便我可以立即将其链接为<img src="somename.jpg"/>和动态生成的图像显示.

I have a dynamically created image and it has an extension ".PHP" (obviously) and that server is not under my control. So I want to redirect "somename.jpg" (on my server) to "remoteserver/dynamicimage.php" (on some remote server not under my control) so that I can right away link it as <img src="somename.jpg"/> and the dynamically generated image is shown.

请让我知道是否可能.

推荐答案

浏览器遵循图像重定向.创建一个名为"somename.jpg"的php文件并添加:

Browsers follows redirects for images. Create a php-file called "somename.jpg" and add:

<?php
header('Location: http://www.otherserver.com/image.php');

在.htaccess中使用Apache指令 ForceType 告诉服务器将.jpg文件作为php处理:

Use the Apache directive ForceType in an .htaccess file to tell the server to process the .jpg file as php:

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

或者如果确实不需要.jpg扩展名,则只需调用文件somename.php.

Or just call the file somename.php if you don't really need the .jpg extension.

您也可以使用 mod_alias 完成此操作,尽管我还没有尝试过:

You could probably accomplish this using mod_alias as well, although I haven't tried it:

Redirect somename.jpg http://www.otherserver.com/image.php

这也将放在.htaccess文件中.

This would go in an .htaccess file as well.

这篇关于指向&lt; img&gt;标记到由PHP动态生成的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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