0

I am trying to access a web service that returns a jpeg image. It requires two variables, time_sent and user_id, in the URL## Heading ##.

Here is my code:

   $ch = curl_init();
   $options =  array(

            CURLOPT_URL => 'www.example.com/service/?time_sent=time&user_id=user',
            CURLOPT_HTTPHEADER => array('Authorization-Token:' . $api_key, 'Content-type: image/jpeg'),
            CURLOPT_ENCODING => "",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HTTPGET => true,
            CURLOPT_CONNECTTIMEOUT => 60,
            CURLOPT_TIMEOUT => 60

        );
    }
    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);

    if(!curl_errno($ch)){
        curl_close($ch);
        $img = imagecreatefromstring($response);
        imagejpeg($img);
        imagedestroy($img);
    }
    else{
        curl_close($ch);
        return curl_error($ch);
    }

Here is my output:

ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC
2!!22222222222222222222222222222222222222222222222222ÿÀÈ•"ÿÄ
ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚<br> %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ
ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ?ê¡ñ…n¦TþÌ)Ÿö« ¾Òü1g¤ýºâ5† ¼7ñW5¢xVÑõhXïØ¿6Ö¦|Wß}¤,&¼øÆ2‰´£.b&^Äè÷s)ùê“xkáÕÔª¯ª\¯÷~uÿâk—³ðóN¬îQ*Ëxq¢]ÂUoø (rÈèWÁ~R˹:ý^³ï<áe•Z¾æþÕ’Ú[$Lå¾ía\Þ*3)o—ýšÖ&lt;Ò(éæð­ŒåêˆÊ+VòþÑ4VÓ„ß2ÿyŒ×›ÔÊû¿Þ¨µ%PÊìÌÕ­Œ§Ìu­u ªíß¿o÷k2æõ.%ûì«þõs¯xïº ¶ê9b(È»s>ÖÜ›æ©lüAqoÕÙ«(¾æçîÔEUºSäˆæŸâ¿ò¼Õº’¤¨®Ž¬µåÙ¾]Õ¥i¬ÜÙºì—å_á¨äÑÓk3|ÕËx·^¢ujþ‹­Å~»ä—ø¿Ú¬Ýy[ûA?º”cÊ8™òîÿj˜?Öí©vî¦lÚû«Qšqí1šŠ‰±E2¡4H•õm«÷k–ø†ÒÞø¢ÊÍÓ÷®êêtiâK®_/Þ¬]7^+ó6+Ä©÷·W$yyKŸÅÌe$B$Ø‹M¹e··i–²µmQ–gŠÙÕ]k*Ù5=YÒßÍÜÎßuj£b¹½ÒY®.õyÚÒÆ•Ÿø–¦¶ø_¬N­-ʲ(þõïxfÓF²‹÷<em>éylt­ö@ªrVð‡,N~{ÈùwXðãØM·gûß5bM¦²¯ÿe^ãâû+ifw ªª¿7ûÕ暌Vêÿ#n¨æ÷¹#ÊqO§ÿµP2íêµÐÏ2ðµ›-»V„Jizvê±5¿Ë÷j©ù~SAŸ("í}Õ,Ëòn¦V½SLÉ䪊`Coq-¼©,mµ–¶ŸWûz'™þµWkµXiÑJÈô´­¹TÕbæÊæÞ(¦’DºÍVô;xµ$µ··\<¿:ÿ³]Ĩ~Ýi...etc

Can anyone tell me what I am doing wrong?

4

1 に答える 1

2

Can anyone tell me what I am doing wrong?

Nothing really, that looks like a healthy JPG :) Send a

header("Content-type: image/jpeg");

before doing imagejpeg($img); and it should work.

于 2013-02-28T21:40:41.870 に答える