You are not logged in.

#1 2010-03-26 14:30:07

thinkinghat
Member
Registered: 2010-03-26
Posts: 2

PHP image display error - Broken image of death

Hi All,

I am a first time poster but a long time user of Arch :)

I've setup a dev environment using Arch and I am learning PHP and trying to develop a webapp.

Currently I am having problems displaying images while playing around with some simple code - Getting the broken image icon.

Below is the code -

<?php
    error_reporting(E_ALL);

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if (isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name']) 
            && $_FILES['photo']['error'] == UPLOAD_ERR_OK) {
                
                if ($_FILES['photo']['type'] == 'image/jpeg') {
                    $tmp_img = $_FILES['photo']['tmp_name'];
                    
                    $image = imagecreatefromjpeg($tmp_img);
                    
                    header('Content-Type: image/jpeg');

                    imagejpeg($image, '', 90);
                    
                    imagedestroy($image);
                } else {
                    echo "Not a valid file!";
                }
        }    
    } else {

?>

<form action="test.php" method="post" enctype="multipart/form-data">
    <label for="photo">User Photo:</label>
    <input type="file" name="photo" />
    <input type="submit" value="Upload a photo" />
</form>

<?php } ?>

When I do a print_r output of the $_FILES array I get the correct stuff:

Array ( [photo] => Array ( [name] => IMG_0304-pola.jpg [type] => image/jpeg [tmp_name] => /tmp/phpplz8js [error] => 0 [size] => 293851 ) )

Oh and here is my GD information:

gd

GD Support    enabled
GD Version    2.0
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.3.12
GIF Read Support    enabled
GIF Create Support    enabled
JPEG Support    enabled
libJPEG Version    unknown
PNG Support    enabled
libPNG Version    1.4.0
WBMP Support    enabled

I am wondering if I am missing anything (spastic typing hands) or permissions somewhere.

Thanks a lot everyone!

Offline

#2 2010-03-26 17:09:39

FOODy
Member
From: Germany
Registered: 2009-10-07
Posts: 5

Re: PHP image display error - Broken image of death

Hm. Works for me with PHP 5.3 and Firefox.

Have you tried to clear the cache?
(Firefox for example has cached the result on my computer)

Offline

#3 2010-03-27 00:16:31

thinkinghat
Member
Registered: 2010-03-26
Posts: 2

Re: PHP image display error - Broken image of death

Ah silly me. Forgot about that sad Thanks a lot for your help FOODy big_smile

Offline

Board footer

Powered by FluxBB