zoukankan      html  css  js  c++  java
  • PHP curl传输文件的版本兼容性

     1     /**
     2      * 存储文件到远程服务器
     3      *
     4      * @param string $filePath
     5      *            文件绝对路径
     6      * @param string $fileSaveUrl
     7      *            存储的远程目标地址
     8      * @param string $fileName
     9      *            存储后的文件名
    10      * @param string $fileType
    11      *            文件的mime类型
    12      */
    13     private function realSave($filePath, $fileSaveUrl, $fileName, $fileType, $port) {
    14         if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
    15             $cfile = curl_file_create ( $filePath, $fileType, $fileName );
    16             $params = array (
    17                     'file' => $cfile
    18             );
    19         }
    20         else{
    21             $params = array (
    22                     $fileName => '@' . $filePath
    23             );
    24         }
    25         $handle = curl_init ( $fileSaveUrl . $fileName );
    26         curl_setopt ( $handle, CURLOPT_PORT, $port );
    27         curl_setopt ( $handle, CURLOPT_POST, 1 );
    28         curl_setopt ( $handle, CURLOPT_POSTFIELDS, $params );
    29         curl_setopt ( $handle, CURLOPT_RETURNTRANSFER, true );
    30         $result = curl_exec ( $handle );
    31         $info = curl_getinfo ( $handle );
    32         curl_close ( $handle );
    33         if ($info ['http_code'] == 201) {
    34             return true;
    35         } else {
    36             return false;
    37         }
    38     }
  • 相关阅读:
    jquery属性
    jquery选择器
    Django的模型
    win7安装RabbitMQ
    阿里云RDS备份的tar格式包恢复到本地自建数据库
    正确使用 Volatile 变量
    深入分析Volatile的实现原理
    volatile和synchronized的区别
    全面理解Java内存模型
    深入理解Feign之源码解析
  • 原文地址:https://www.cnblogs.com/Moon-Face/p/5288212.html
Copyright © 2011-2022 走看看