tags:

views:

76

answers:

2

I'm working with WampServer Version 2.0 on Windows XP and FireFox 3.6.8.

I'm trying to get image content via PHP script like this:

HTML:

<img src='temp_get_file.php' alt='picture not found' />

PHP: (temp_get_file.php)

<?php
header('Content-Type: image/png');
$img = imagecreatefromjpeg("1.png");
imagejpeg($img);
imagedestroy($img);
?>

The HTML, PHP, and 1.png files are located in the www directory of WampServer.

Unfortunately, I got this error (in HTTPFOX plugin in FireFox):

Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED)

and I see "picture not found".

If I put the image in HTML directly like this:

<img src='1.png' alt='picture not found' />

everything works fine.

What's wrong with my PHP ?

+4  A: 

This may just be a problem in your example, but this won't work:

imagecreatefromjpeg("1.png")
                 ^      ^
               JPEG != PNG
deceze
I'm so....... Thanks a lot :)
Misha Moroshko
+1  A: 

Not with your PHP actually but with your PHP skills :)
Some advises to improve

  1. you have to debug your application instead of asking community.
    To do so, you have to
    a) request your image file directly, by typing temp_get_file.php into browsers address bar, to let you see output of the script
    b) put Content-Type header output as low in the code, as possible, to let PHP sent text/html in case of some errors
    c) have displaying errors on
    or
    instead of all this above you can turn logging errors on and catch the error in the error log.
    both methods will let you to get PHP error message - a thing you really need here, instead of useless firefox complains.
    and this error message is pretty clear - wrong file format.

  2. if it's the only thing what your script does, you don't need all these GD functions. thats useless. if you need to output some file to the browser, just do it. readfile("1.png") is enough

Col. Shrapnel