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条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装