user2302779
user2302779

Reputation: 1

Image "[blah]" cannot be displayed because it contains errors

             <?php
                ob_start();
                session_start();
                require_once('name.php');
                   if(!isset($_GET['e']))
                   {
                    header('HTTP/1.1 204 No Content');
                    exit();
                    }
                    if(empty($_SESSION['id']))
                    {
                    header('Location: login.php');
                        exit();
                    }
                    $id=$_GET['e'];

                    //database login information removed

                    $statement2=$db->prepare('select * from event2 where id=:id and userid=:uid');
                    $statement2->execute(array('id' => $id,
                               'uid' => $_SESSION['id']));
                    if($statement2->rowCount()==0)
                    {
                header('HTTP/1.1 204 No Content');
                exit();
                    }
                    $row=$statement2->fetch();
                    $image=$row['image'];
                    $realimage=imagecreatefromstring($image);


                header('Content-type: image/jpeg');
               $realimage;
                ob_end_flush();
                ?>

I'm receiving an "Image 'image link' cannot be displayed because it contains errors." I've tried changing the content header position around to various places and cannot get it to work. I've downloaded the image straight from the database and it does reproduce properly. When opening the page in chrome, I'm presented with a tiny little green stock picture.

Upvotes: 0

Views: 2114

Answers (2)

bwoebi
bwoebi

Reputation: 23787

What about outputting the image?

imagejpeg($realimage);

You're missing an imagejpeg before the $realimage;. (imagejpeg or the other appropriate image* functions for outputting.)


By the way, why don't you output directly $image (via echo) instead of first parsing the image data as image?

Upvotes: 1

Marcel Korpel
Marcel Korpel

Reputation: 21763

You have spaces before the <?php opening tag. Remove them.

Upvotes: 1

Related Questions