DrStrange Posted July 10, 2009 Share Posted July 10, 2009 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? Link to comment https://forums.phpfreaks.com/topic/165531-solved-the-inverse-of-content-disposition-attachment-showing-php-as-jpg-files/ Share on other sites More sharing options...
celsoendo Posted July 11, 2009 Share Posted July 11, 2009 You have to send correct http headers. If you want to send a jpg image you can do something like this: <?php $img = "my_image.jpg"; header("Content-type: image/jpeg"); readfile($img); ?> Link to comment https://forums.phpfreaks.com/topic/165531-solved-the-inverse-of-content-disposition-attachment-showing-php-as-jpg-files/#findComment-873290 Share on other sites More sharing options...
DrStrange Posted July 11, 2009 Author Share Posted July 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/165531-solved-the-inverse-of-content-disposition-attachment-showing-php-as-jpg-files/#findComment-873340 Share on other sites More sharing options...
DrStrange Posted July 11, 2009 Author Share Posted July 11, 2009 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... Link to comment https://forums.phpfreaks.com/topic/165531-solved-the-inverse-of-content-disposition-attachment-showing-php-as-jpg-files/#findComment-873349 Share on other sites More sharing options...
Andy-H Posted July 11, 2009 Share Posted July 11, 2009 They probably only check the extension in their script so just modrewrite it to a .jpg, then input your URL... Link to comment https://forums.phpfreaks.com/topic/165531-solved-the-inverse-of-content-disposition-attachment-showing-php-as-jpg-files/#findComment-873351 Share on other sites More sharing options...
DrStrange Posted July 11, 2009 Author Share Posted July 11, 2009 Hm, yes. I just tried an .htaccess redirect (nonexistent jpg filename to the php avatar filename) and it works now. Thanks everyone. Link to comment https://forums.phpfreaks.com/topic/165531-solved-the-inverse-of-content-disposition-attachment-showing-php-as-jpg-files/#findComment-873354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.