Jump to content

[SOLVED] the inverse of Content-Disposition -> attachment? (showing php as jpg files)


DrStrange

Recommended Posts

Hi,

 

There is this forum I post my avatar to. Problem is, I want to randomise my avatar using PHP to show a different one each time someone visits. Problem is, the forum only accepts JPG extensions, so posting an image with the address avatar.php does not work... I have to use avatar.jpg.

 

1) The PHP code is working.

2) I used AddType application/x-httpd-php .jpg in the .htaccess file to run php code in files with jpg format (this works too)

 

Only problem, when I access avatar.jpg firefox wants to save it (download it) instead of showing the image. I did some digging and came up to this page :

 

http://www.gnucitizen.org/blog/content-disposition-hacking/

 

It shows how to download files instead of showing them, but I need to do the inverse. Showing them instead of downloading. I am stuck at this point and Google can't find anything useful on this subject.

 

Can anybody help?

I am already sending the right headers. Those are the last 2 lines of my code :

 

	header('Content-type: image/jpeg');
imagejpeg($image_resized);	

 

See for yourself (the php file disguised as jpg, triggers a download) :

 

http://www.codequantum.com/zeno/avatar.jpg

 

The EXACT same file as php (which works correctly) :

 

http://www.codequantum.com/zeno/avatar.php

Ok I think the problem comes from .htaccess and not PHP itself. Because :

 

I uploaded an image (a real image) :

 

http://www.codequantum.com/zeno/av.jpg

 

And when I try to access it, it tries to download instead of displaying.

 

I also created a test file :

 

http://www.codequantum.com/zeno/test.jpg

 

which is a php file containing the code :

 

<?php
$img = "av.jpg";

header("Content-type: image/jpeg");
readfile($img);
?>

 

And it also tries to download.

 

Is it possible to serve a file in place of another with .htaccess? Maybe i can serve the php file (that generates the image) when someone tries to access image.jpg...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.