php curl 上传多文件,怎么弄

php curl 上传多文件,怎么弄,第1张

下面是一段示例代码:

<?php

// 注: PHP 5.5.0起,文件上传建议使用CURLFile代替@

// 多文件上传

$data = array(

'input_file[0]' =>new CURLFile('d:/1.txt', 'text/plain', 'testfile.txt'),

'input_file[1]' =>new CURLFile('d:/2.txt', 'text/plain'),

'input_file[2]' =>new CURLFile('d:/3.txt', 'text/plain'),

)

$ch = curl_init('http://demo.zjmainstay.cn/php/curl/curlUploadHandler.php')

curl_setopt($ch, CURLOPT_POST, 1)

curl_setopt($ch, CURLOPT_POSTFIELDS, $data)

curl_exec($ch)

如果你的版本比较低,文件部分使用:

'input_file[0]' =>'@d:/1.txt',

这样既可。

$post_data = array(

"media"=>"E:\WORKS/yy.jpg"

)

$url="http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=$acctoken&type=image"

$ch = curl_init()

curl_setopt($ch, CURLOPT_POST, 1)

curl_setopt($ch, CURLOPT_URL,$url)

curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data)

ob_start()

curl_exec($ch)

$result = ob_get_contents()

ob_end_clean()

echo $result


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/7942873.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存