duanchuopi2298 2017-04-11 14:52
浏览 32
已采纳

无法显示结果图像(PHP代码)

i an trying to get the result(image) from url but there is some thing error in the code my code is:

<?php
if(isset($_POST['submit']))
{
$url= $_POST['url'];
$qrurl= 'http://www.qr-code-generator.com/phpqrcode/getCode.php?
cht=qr&chl='.$url.'&chs=180x180&choe=UTF-8&chld=L|0';
$result = file_get_contents("$qrurl");
echo $result;
}
else
{
echo"<form method='post' action='index.php' >
<input name='url' class='material' placeholder='Enter url...' type='url'autofocus/></br><br>
<input name='submit' id='submit' type='submit' value='submit'/></br><br>
</form>
";
}
?>

the above code displays nothing but when i open the url in browser it displays qr code.

  • 写回答

1条回答 默认 最新

  • doumu1951 2017-04-11 15:07
    关注

    You need a (PNG) header since that is the type of file it is creating, and to make sure the URL is in one line and not broken into two; very important.

    <?php 
    if(isset($_POST['submit']))
    {
    $url= $_POST['url'];
    $qrurl= 'http://www.qr-code-generator.com/phpqrcode/getCode.php?cht=qr&chl='.$url.'&chs=180x180&choe=UTF-8&chld=L|0';
    $result = file_get_contents("$qrurl");
    echo $result;
    
    header ('Content-Type: image/png');
    exit;
    
    }
    else
    {
    echo"<form method='post' action='index.php' >
    <input name='url' class='material' placeholder='Enter url...' type='url'autofocus/></br><br>
    <input name='submit' id='submit' type='submit' value='submit'/></br><br>
    </form>
    ";
    
    }
    

    You may also have to add ob_start(); at the top after the opening <?php.

    And that the file is not encoded with a byte order mark. This too will throw an error.

    The file can be encoded as ANSI or UTF-8 without BOM.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作