curl 上传

WBOY
Release: 2016-06-23 14:20:51
Original
982 people have browsed it

curl

求一组curl上传代码

回复讨论(解决方案)

header("Content-Type:text/html;charset=utf-8");
/**
 * 下面来看下如果通过cURL发送post请求来实现文件上传。
 * 就拿深入浅出PHP下的文件上传中的文件上传例子来演示
 * 在深入浅出php下的文件上传中,是通过表单的提交来实现文件上传的
 * 那么通过cURL怎么来实现呢?
 **/
$url = "http://www.360weboy.me/upload.php";

$post_data = array (
  "attachment" => "@E:/jackblog/boy.jpg"
);

//初始化cURL会话
$ch = curl_init();

//设置请求的url
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//设置为post请求类型
curl_setopt($ch, CURLOPT_POST, 1);

//设置具体的post数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$response = curl_exec($ch);
curl_close($ch);

print_r($response);

?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template