zoukankan      html  css  js  c++  java
  • PHP 上传文件到其他服务器

    PHP 上传文件到其他服务器

    标签(空格分隔):

    安装Guzzle类库

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

    文件上传

    <?php
        use GuzzleHttpClient;
        
        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;
    }
  • 相关阅读:
    深入分析 Java 中的中文编码问题
    随便写写20160411
    Linux GDB 程序调试工具使用详解
    「美国花好几亿造出太空圆珠笔后,发现苏联航天员用铅笔」的故事真实吗?
    verynginx部署
    harbor私有仓库部署
    rancher学习
    harbor部署
    zabbix-proxy docker
    NFS部署
  • 原文地址:https://www.cnblogs.com/yanweifeng/p/11066035.html
Copyright © 2011-2022 走看看