解决方案 »

  1.   

    1、确认没有BOM 头或其他非图片数据
    从截图上看应该没有
    2、输出正确的数据类型声明
    从代码上看,的确没有
      

  2.   

    这个不是乱码!是文件流,你把这个写入的到图片文件,或者之间通过html的img标签显示到浏览器中,应该就是一张图片了。
      

  3.   

    写到img标签的src属性依旧乱码呀
      

  4.   

    写到img标签的src属性依旧乱码呀

    将数据流写入文件
      

  5.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
      

  6.   

    写到img标签的src属性依旧乱码呀
      

  7.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
    Php代码和楼主的基本一致,html代码是这样的
     <img style="margin:20px" width="280" height="140" src="{:url('index/index')}"/>,
    这是curl代码
    function doCurl($url,$data=[],$type=0)
    {
    $ch=curl_init();//初始化一个curl对话并返回一个curl句柄
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//获取页面内容,不直接输出
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type==1)
    {
    curl_setopt($ch,CURLOPT_POST,1);//type为1时post方式提交
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//
    }

    //执行curl
    $output=curl_exec($ch);

    //释放句柄
    curl_close($ch);
    //返回执行结果
    return $output;
    }
    是因为文件流出问题了吗
      

  8.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
    Php代码和楼主的基本一致,html代码是这样的
     <img style="margin:20px" width="280" height="140" src="{:url('index/index')}"/>,
    这是curl代码
    function doCurl($url,$data=[],$type=0)
    {
    $ch=curl_init();//初始化一个curl对话并返回一个curl句柄
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//获取页面内容,不直接输出
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type==1)
    {
    curl_setopt($ch,CURLOPT_POST,1);//type为1时post方式提交
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//
    }

    //执行curl
    $output=curl_exec($ch);

    //释放句柄
    curl_close($ch);
    //返回执行结果
    return $output;
    }
    是因为文件流出问题了吗把你index方法也贴出来看看。还有你img标签的图片你给个截图吧!
      

  9.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
    Php代码和楼主的基本一致,html代码是这样的
     <img style="margin:20px" width="280" height="140" src="{:url('index/index')}"/>,
    这是curl代码
    function doCurl($url,$data=[],$type=0)
    {
    $ch=curl_init();//初始化一个curl对话并返回一个curl句柄
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//获取页面内容,不直接输出
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type==1)
    {
    curl_setopt($ch,CURLOPT_POST,1);//type为1时post方式提交
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//
    }

    //执行curl
    $output=curl_exec($ch);

    //释放句柄
    curl_close($ch);
    //返回执行结果
    return $output;
    }
    是因为文件流出问题了吗把你index方法也贴出来看看。还有你img标签的图片你给个截图吧!
    public static function getMapImage($center)
    {
    $data=[
    'ak'=>config('map.ak'),
    'width'=>config('map.width'),
    'height'=>config('map.height'),
    'center'=>$center,
    'ers'=>$center,
    ];
    $url=config('map.baidu_map_url').config('map.staticimage')."?"
                        .http_build_query($data);

    $res=doCurl($url);
    return $res;
    }
    这是在扩展库中写的,在Index方法中调用
    public function index()
    {
           return \Map::getMapImage("山东威海环翠区文化西路");
    }
    抱歉img这里一直上传图片失败
      

  10.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
    Php代码和楼主的基本一致,html代码是这样的
     <img style="margin:20px" width="280" height="140" src="{:url('index/index')}"/>,
    这是curl代码
    function doCurl($url,$data=[],$type=0)
    {
    $ch=curl_init();//初始化一个curl对话并返回一个curl句柄
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//获取页面内容,不直接输出
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type==1)
    {
    curl_setopt($ch,CURLOPT_POST,1);//type为1时post方式提交
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//
    }

    //执行curl
    $output=curl_exec($ch);

    //释放句柄
    curl_close($ch);
    //返回执行结果
    return $output;
    }
    是因为文件流出问题了吗把你index方法也贴出来看看。还有你img标签的图片你给个截图吧!
    public static function getMapImage($center)
    {
    $data=[
    'ak'=>config('map.ak'),
    'width'=>config('map.width'),
    'height'=>config('map.height'),
    'center'=>$center,
    'ers'=>$center,
    ];
    $url=config('map.baidu_map_url').config('map.staticimage')."?"
                        .http_build_query($data);

    $res=doCurl($url);
    return $res;
    }
    这是在扩展库中写的,在Index方法中调用
    public function index()
    {
           return \Map::getMapImage("山东威海环翠区文化西路");
    }
    抱歉img这里一直上传图片失败你把return改成echo看看?我这边用return的话是得不到数据的。方法不会返回数据流
      

  11.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
    Php代码和楼主的基本一致,html代码是这样的
     <img style="margin:20px" width="280" height="140" src="{:url('index/index')}"/>,
    这是curl代码
    function doCurl($url,$data=[],$type=0)
    {
    $ch=curl_init();//初始化一个curl对话并返回一个curl句柄
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//获取页面内容,不直接输出
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type==1)
    {
    curl_setopt($ch,CURLOPT_POST,1);//type为1时post方式提交
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//
    }

    //执行curl
    $output=curl_exec($ch);

    //释放句柄
    curl_close($ch);
    //返回执行结果
    return $output;
    }
    是因为文件流出问题了吗把你index方法也贴出来看看。还有你img标签的图片你给个截图吧!
    public static function getMapImage($center)
    {
    $data=[
    'ak'=>config('map.ak'),
    'width'=>config('map.width'),
    'height'=>config('map.height'),
    'center'=>$center,
    'ers'=>$center,
    ];
    $url=config('map.baidu_map_url').config('map.staticimage')."?"
                        .http_build_query($data);

    $res=doCurl($url);
    return $res;
    }
    这是在扩展库中写的,在Index方法中调用
    public function index()
    {
           return \Map::getMapImage("山东威海环翠区文化西路");
    }
    抱歉img这里一直上传图片失败你把return改成echo看看?我这边用return的话是得不到数据的。方法不会返回数据流
    exit也是,返回不到数据,必须在view层新建模板,然后return $this->fetch()将数据返回,模板中处理时通过a标签的href属性才可以查看到
      

  12.   

    写到img标签的src属性依旧乱码呀
    能给我看下你的图片链接地址吗?
    Php代码和楼主的基本一致,html代码是这样的
     <img style="margin:20px" width="280" height="140" src="{:url('index/index')}"/>,
    这是curl代码
    function doCurl($url,$data=[],$type=0)
    {
    $ch=curl_init();//初始化一个curl对话并返回一个curl句柄
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//获取页面内容,不直接输出
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type==1)
    {
    curl_setopt($ch,CURLOPT_POST,1);//type为1时post方式提交
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//
    }

    //执行curl
    $output=curl_exec($ch);

    //释放句柄
    curl_close($ch);
    //返回执行结果
    return $output;
    }
    是因为文件流出问题了吗把你index方法也贴出来看看。还有你img标签的图片你给个截图吧!
    public static function getMapImage($center)
    {
    $data=[
    'ak'=>config('map.ak'),
    'width'=>config('map.width'),
    'height'=>config('map.height'),
    'center'=>$center,
    'ers'=>$center,
    ];
    $url=config('map.baidu_map_url').config('map.staticimage')."?"
                        .http_build_query($data);

    $res=doCurl($url);
    return $res;
    }
    这是在扩展库中写的,在Index方法中调用
    public function index()
    {
           return \Map::getMapImage("山东威海环翠区文化西路");
    }
    抱歉img这里一直上传图片失败你把return改成echo看看?我这边用return的话是得不到数据的。方法不会返回数据流
    我发现把文件保存到本地就可以实现了
    public function map()
    {
            $return_content = \Map::getMapImage("山东威海环翠区文化西路山东大学");        $str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
            str_shuffle($str);
            $name=substr(str_shuffle($str),26,10);
            $dir_name='baidu map/'.$name.'.jpg';        $filename =$dir_name;
            $fp= @fopen($dir_name,"w");
            fwrite($fp,$return_content);        fclose($fp);
          // return $dir_name;
        }
    至于上面为什么不能实现还是不明白;