Table of Contents
回复内容:
Home Backend Development PHP Tutorial post - php curl上传文件如何像表单一样指定其name值

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'=&gt;'@E:\WWW\6\0604\1.jpg')
    );
    $data=curl_exec($ch);
    curl_close($ch);
    echo $data;
?&gt;  
</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'=&gt;'@E:\WWW\6\0604\1.jpg')
    );
    $data=curl_exec($ch);
    curl_close($ch);
    echo $data;
?&gt;  
</code>
Copy after login
Copy after login

<code>curl_setopt($ch, CURLOPT_POSTFIELDS, array('media'=&gt;'@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

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

CakePHP Creating Validators

See all articles