1)在 php 5.5.0 之前,如果使用 @+文件路径的文件上传文件,具体看这里:http://www.cnblogs.com/tujia/p/5938463.html

2)php 5.5.0 之后已弃用这个方法,想要使用 curl 上传文件,可以使用 curlFile 对象来实现,面向过程化的函数是 curl_file_create

3)写法并没有和普通的 curl 有什么不同,只是把参数中的文件,改成 curFile 就行,完整例子如下:

$parameters['file'] = curl_create_file($file_path);

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $parameters );
$response    = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

 

相关文章:

  • 2021-08-18
  • 2022-12-23
  • 2021-06-17
  • 2021-11-04
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2021-12-23
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2021-10-30
相关资源
相似解决方案