您的位置:首页 > 其它

curl入门知识之抓取二进制数据

2010-08-12 21:29 316 查看
<?php
// Allocate a new cURL handle
$ch = curl_init("http://www.designmultimedia.com/intro.jpg");
if (! $ch) {
die( "Cannot allocate a new PHP-CURL handle" );
}
// We'll be returning this transfer, and the data is binary
// so we don't want to NULL terminate
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
// Grab the jpg and save the contents in the $data variable
$data = curl_exec($ch);
// close the connection
curl_close($ch);
// Set the header to type image/jpeg, since that's what we're
// displaying
header("Content-type: image/jpeg");
// Output the image
print( $data );
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: