Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP/PNG query

Options
  • 07-06-2006 1:39am
    #1
    Moderators, Society & Culture Moderators Posts: 10,247 Mod ✭✭✭✭


    I'm trying to upload a folder (with two PNG files and one .htaccess file) that uses php code to create a dynamic image which will list the latest posts in my blog, but when I do upload the folder and go to the link for the image, I only get the option to download the file and not view it in my browser

    What do I need to do? I've been told I might need to create a PNG library in my hosting account (what does that mean, and what does it do?), or is it something to do with the PHP code that's being used?

    Thanks for the help.


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    How are you linking to it? It should be using <img src="x.php"...> rather than <a> .

    Does the php specify type of content to be returned? [header('Content-Type: image/png')]

    Check if Imagemagick or GD is installed - and version. (phpinfo)


  • Moderators, Society & Culture Moderators Posts: 10,247 Mod ✭✭✭✭flogen


    Karoma wrote:
    How are you linking to it? It should be using <img src="x.php"...> rather than <a> .

    Does the php specify type of content to be returned? [header('Content-Type: image/png')]

    Check if Imagemagick or GD is installed - and version. (phpinfo)

    Well I mean when I go to the link itself (www.adam-maguire.com/blog/sigpic/sig.png); it's the same code that Danger uses for his TCAL button (see here) and the header says image/png too...
    How do I check if those two are installed? Where do I need to go (MySQL databases? Sorry really lost with all this!)


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    The problem is the handler for .png files.

    The normal setup for PHP with apache is to only process files that end in .php (and php3 and some others). The standard request works as follows;

    1. You request page mypage.php
    2. Apache recognises the .php extension.
    3. Apache passes the php file to the PHP interpreter
    4. The interpreter spits the interpreted (now HTML) php file back to apache.
    5. Apache sends the HTML to your browser.

    But with this .png file, Apache sees the PNG extension in step 2, and jumps straight to step five - outputting it to the browser. If you download your link above, and open it in notepad, you'll see your PHP code.

    You could add in the PHP handler for the .png extension, but I wouldn't recommend it. A far simpler solution, is to simply rename the above file and change the extension to .php. Then your image link becomes
    <img src="www.adam-maguire.com/blog/sigpic/sig.php">

    The reason I wouldn't recommend it is as follows: Say sometime in the future, you have an image upload facility on your website. You've been happily running this site for years, and your little sig has evolved, but is still using the .png extension. You've totaly forgotten about how you set up apache to do this. Somebody notices this, and one day uploads a file with a .png extension, but containing PHP code which does whatever their heart desires...


  • Moderators, Society & Culture Moderators Posts: 10,247 Mod ✭✭✭✭flogen


    Thanks for that Seamus, it's worked a treat (and I just realised I hadn't changed the RSS feed in the code, so I was getting TCAL's posts for a while :D)

    Thanks again


Advertisement