dpfln86244 2014-10-30 17:49
浏览 45
已采纳

通过php问题输出图像

I am aware that this is probably a very trivial problem which I just can't seem to get right although I have spent the last few hours crawling the web..

I have a file image_get.php which is supposed to display an image file "keepcalm.png" that is located in the same directory as the php file.

I am using a class to handle all the image related actions.

image_get.php

<?php
   include "classes/image.class.php"; 
   include "classes/database.class.php";
   $database_sso = new database('SSO'); //will be needed later and is dummy for now
   $testimage = new image($database_sso, "1"); //parameters are dummy for now
   $testimage->show_image();
?>

image.class.php

<?php

class image{
   private $database_image;     //Image Database containing all images
   private $imageid;            //ID of Image in Database
   private $filepath;           //Path to image file


//PUBLIC FUNCTIONS  
   public function __construct($database, $imageid){
     $this->database_image = $database;     //Right now this is just a placeholder
     $this->imageid = $imageid;         //Right now this is just a placeholder

   }

    public function show_image(){

    $remoteImage = $this->get_local_link_from_id($this->imageid);  // Right now this returns "keepcalm.png"

    header('Content-Type: image/x-png')
    $returnstring = readfile($remoteImage);

}
 //PRIVATE FUNCTIONS
private function get_local_link_from_id($imageid){

    $local_link = "keepcalm.png"; //dummy for now
    return $local_link;
}


}



?>

The output I get is complet gibberish as can be seen here -> http://niederrad.no-ip.org/portal/image_get.php

What am I missing? I have tried lots of iterations of the above and am completely clueless as to how I should proceed..

  • 写回答

2条回答 默认 最新

  • douyoufan7881 2014-10-30 19:17
    关注

    The Problem was with BOM which I find very strange as I was sure I had checked to not encode with BOM...

    How to fix "Headers already sent" error in PHP

    A very good suggestion from Cheery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?