开发者

what does curlopt_binarytranfer exactly mean?

开发者 https://www.devze.com 2023-03-05 19:28 出处:网络
i dont understand what is the difference between CURLOPT_RETURNTRANSFER AND CURLOPT_BINARYTRANSFER i wrote a s开发者_JAVA技巧cript to check it

i dont understand what is the difference between

CURLOPT_RETURNTRANSFER AND
CURLOPT_BINARYTRANSFER

i wrote a s开发者_JAVA技巧cript to check it

<?php
$image_url = "http://localhost/curl/img1.png";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $image_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
curl_close($ch);
header("Content-type: image/jpeg");
print $image;
?>

in this case i get the image displayed in the browser if i remove the line

curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

i still get the image displayed in the browser.

and now if i remove the line

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

then iget binary data display in browser(looks like garbage) in both cases whether i remove curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); or i dont remove. then what difference does this option CURLOPT_BINARYTRANSFER make?


It looks like CURLOPT_BINARYTRANSFER isn't used by PHP anymore, if I am understanding this PHP bug report and resolution correctly.

https://bugs.php.net/bug.php?id=55635


With this kind of curl we are looking at two transfers:

  1. data travels from the target host to our PHP host
  2. it is sent from our PHP host to our browser.

By removing header("Content-type: image/jpeg"); you deny the browser the clue as to how the content that follows should be interpreted. This has nothing to do with CURLOPT_BINARYTRANSFER which affects the first transfer.

0

精彩评论

暂无评论...
验证码 换一张
取 消