2

PHPで動的PNG画像を作成しました。PNG 拡張子を使用するために、次の内容の .htaccess-File を作成しました。

AddType application/x-httpd-php .png

私のローカル XAMPP サーバーではすべてが完璧に機能しますが、Web サーバーにファイルをアップロードした後は機能しなくなります。ファイルにアクセスすると、ファイルの PHP コードが表示されます。

これらは、両方のサーバーからの 2 つの異なる回答です:

ローカル サーバー:

HTTP/1.1 200 OK
Date: Tue, 16 Oct 2012 21:51:58 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
Last-Modified: Sat, 07 Feb 2009 11:47:04 GMT
Etag: "9000000024598-1e66-46252b23c9e00"
Accept-Ranges: bytes
Content-Length: 7782
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/x-icon

ウェブサーバー:

HTTP/1.1 200 OK
Date: Tue, 16 Oct 2012 21:55:17 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r
Last-Modified: Tue, 16 Oct 2012 21:21:56 GMT
Etag: "db0f1b0-afc-4cc33be6befa5"
Accept-Ranges: bytes
Content-Length: 2812
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Content-Type: application/x-httpd-php

そのため、どういうわけかファイルは解析されません。ここからどこから始めればよいか本当にわかりません。

4

2 に答える 2

5

.htaccess次のように RewriteEngine でa を使用する方がよいと思います。

RewriteEngine On
RewriteBase /directory/to/dynamic_image
RewriteRule ^logo\.png$ logo.php

またはすべての .php ファイルの場合:

RewriteEngine On
RewriteBase /directory/to/dynamic_image
RewriteRule ^(.+)\.png$ $1.php
于 2012-10-16T22:23:03.433 に答える
2

PHPファイルで、ヘッダーをpng画像として設定します(ページへの出力の前に):

<?php
header('Content-Type: image/png');
// image generating code here.......
?>

これにより、.htaccess エントリが不要になります。

于 2012-10-16T22:29:09.667 に答える