bool curl_setopt ( resource $ch , int $option , mixed $value ) 为给定的cURL会话句柄设置一个选项

详细介绍请到:http://www.php.net/manual/zh/function.curl-setopt.php

我的例子:

#curl_upload_file.php
<?php

$ch = curl_init();

//$data = array('name'=>'Foo', 'file'=>'@E:/wamp/www/test/test.png');   //php5.5以下版本使用(包括5.5)
$args['file'] = new CurlFile(realpath('test.png'));                     //php5.5以上版本使用(包括5.5)

curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/file.php');        //第三個參數為要提交的接口,可以省略這一行,直接將接口url寫到curl_init()中
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);   

curl_exec($ch);

 #file.php

<?php
print_r($_POST);
print_r($_FILES);

 参见:

如果设置多个option值得话,没必要写多个curl_setopt()函数来设置,可以用curl_setopt_array()一起设置

相关文章:

  • 2021-07-21
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2022-02-26
  • 2021-11-14
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2021-09-09
  • 2021-10-17
  • 2022-12-23
  • 2021-11-29
  • 2021-04-10
  • 2022-12-23
相关资源
相似解决方案