duanpi7578 2015-07-25 10:10
浏览 41
已采纳

同时打印图像和字符串

This is maybe looks stupid question. But I'm having trouble to print both image and string(s) in web page.

My codes:

<?php
    $file = 'uploadedimages/' . end(end($collectedResult));
    // $file='demo.gif';
    if(file_exists($file)){
        header('Content-Type:image/jpeg');
        header('Content-Transfer-Encoding: base64');
        //  $data=base64_encode(file_get_contents($file));
        //  echo $data;
        $im = imagecreatefromjpeg($file);
        imagejpeg($im);
        imagedestroy($im);
    }
    else
        echo 'No such file';

    header('Content-Type: text/html; charset=utf-8');
    echo '<br><p>' . json_encode($collectedResult, JSON_UNESCAPED_UNICODE) . '</p>';
?>

With these codes image's showing in browser. It's OK. But some json strings aren't showing.

I don't know where I should put the header('Content-Type: text/html; charset=utf-8'); and/or header('Content-Type:image/jpeg'); line(s).

Thanks.

  • 写回答

3条回答 默认 最新

  • doulan1073 2015-07-25 10:17
    关注

    You can't use header('content type') more than one time . if your objetive is download a image with text on it search for PHP image framework , if you just want to print a image and a text renderit using <img src='<?PHP echo $imageurlordata?>'> and then the text you can also do someting like this

    $data = base64_encode(file_get_contents($file));
    //  echo '<img src="image/base64:'.$data.'">';  // incorrect syntax
    echo '<img src="data:image/jpeg;base64,'.$data.'">'; // you can change jpeg as png, gif or smth else...
    

    or just use image url. I'm on phone sorry if there's any typo, hope its help you.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?