Table of Contents
post - php curl上传文件如何像表单一样指定其name值
Jun 06, 2016 pm 08:33 PM
curl
php
post
在html上传中需要指定
<code><input type="file" name="media" id="file"> </code>
Copy after login
Copy after login
那么在curl上传文件我该怎么设置其name值为media呢?
<code><?php $ch=curl_init('https://api.weixin.qq.com/cgi-bin/media/upload?access_token=123456&type=image'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array('name'=>'media','media'=>'@E:\WWW\6\0604\1.jpg') ); $data=curl_exec($ch); curl_close($ch); echo $data; ?> </code>
Copy after login
Copy after login
回复内容:
在html上传中需要指定
<code><input type="file" name="media" id="file"> </code>
Copy after login
Copy after login
那么在curl上传文件我该怎么设置其name值为media呢?
<code><?php $ch=curl_init('https://api.weixin.qq.com/cgi-bin/media/upload?access_token=123456&type=image'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, array('name'=>'media','media'=>'@E:\WWW\6\0604\1.jpg') ); $data=curl_exec($ch); curl_close($ch); echo $data; ?> </code>
Copy after login
Copy after login
<code>curl_setopt($ch, CURLOPT_POSTFIELDS, array('media'=>'@E:\WWW\6\0604\1.jpg')); </code>
Copy after login
等同于
<code><input type="file" name="media"> </code>
Copy after login
数组中的 键 ‘media’ 其实就是 input 中的 name
我是注册了一个账号,进来给您点个赞!!!谢谢
学习了,还真没这么用过呢
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

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian
