码迷,mamicode.com
首页 > Web开发 > 详细

PHP 上传文件到其他服务器

时间:2019-06-21 18:23:29      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:this   quic   发送   filename   服务器   http   fun   tps   The   

PHP 上传文件到其他服务器

标签(空格分隔):

安装Guzzle类库

**guzzle**  是发送网络请求的类库
composer安装:**composer require guzzlehttp/guzzle**
中文文档[**https://guzzle-cn.readthedocs.io/zh_CN/latest/quickstart.html**]

文件上传

<?php
    use GuzzleHttp\Client;
    
    public $upload_type;  // 发送类型 'image|video|file'
    
    public function shopUpload ($name)
    {
        $file = fopen($_FILES[$name]['tmp_name'], 'r')
        $response = (new Client())->request(
            'POST',    //post 请求
            'http://www.xxx.cm/upload',
            [
                // name: (必须,字符串) 映射到表单字段的名称。
                // contents: (必须,混合) 提供一个字符串,可以是 fopen 返回的资源、或者一个
                
                'multipart' => [   //设置
                    [
                        'name'     => $name,
                        'contents' => $file,
                        'filename' => $_FILES[$name]['name'],
                        'type' => $_FILES[$name]['type']
                    ],
                    [
                        'name' => 'file_name',   // 上传表单的name值
                        'contents' => $name
                    ],
                    [
                        'name' => 'upload_type',  // 上传文件类型
                        'contents' => $this->upload_type,
                    ],
                ]
            ]
        );
        $resultMap = json_decode($response->getBody()->getContents(), true);
    }
    
    
    

服务器接收

function upload ()
{
    直接获取 $_FILES;
}

PHP 上传文件到其他服务器

标签:this   quic   发送   filename   服务器   http   fun   tps   The   

原文地址:https://www.cnblogs.com/yanweifeng/p/11066035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!