dswwuo1223 2011-07-28 07:04
浏览 81
已采纳

使用curl检索图像 - php(issue)

I need to retrieve image from database and store it to a folder. Once I used copy function with direct URL file-access to get the image from database..But it didn't work in our server. because allow_url_fopen is off in our server.. So now I am trying curl function to get the image..

This is my code

  $curl = curl_init("http://localhost/matrimony/admin/getImage.php?id=24");
  curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($curl, CURLOPT_HEADER, 0);
  if(($data = curl_exec($curl)) === false)
        echo "curl error";
  else{
    $im = imagecreatefromstring($data);
    if ($im !== false) {
        header('Content-Type: image/jpeg');
        imagejpeg($im);
        imagedestroy($im);
    }
    else {
        echo 'An error occurred.';
    }
    //return $data;
  }
  curl_close ($curl);

The result is

ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC    $.' ",#(7),01444'9=82<.342ÿÛC  2!!22222222222222222222222222222222222222222222222222ÿÀXµ"ÿÄ ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ?…Z¬+UUj™Z€-+TŠÕ]Z¤V ¨ÝQ«S•¨Û¨ÝMf¢€ Õ½£émÛ©×kmýÚ·ðÿ´Õ6›£­º­ÅÜj× þ­~òÇÿÙU‹Ûæó>ÏÍ'ñ7÷hK™$™¾Ëlß¼eûßÝ_þ

and my getImage code is

    $image = $_GET['id'];
    $rs = mysql_query("select ImgData from tblphotos where PhotoId=$image");
$n=mysql_num_rows($rs);
if($n>0)
{
    $row = mysql_fetch_assoc($rs);
    $imagebytes = $row['ImgData'];
    header("Content-type: image/jpeg");
    print $imagebytes;
}

Is there any mistakes in my code?. I don't know what I have to do..

  • 写回答

1条回答 默认 最新

  • dongxuxian6930 2011-07-28 07:22
    关注

    php.net/manual/de/function.imagejpeg.php second parameter if you want to save it to a file (should be an answer and not a comment

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

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用