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     }
  • 相关阅读:
    PLSQL13
    01.Spring引入
    验证码重构
    短信验证码登录思路
    记住我 token保存到数据库
    图形验证码及其重构
    个性化用户认证流程
    01.Spring Security初识,表单认证
    堆和栈的区别
    系统分析与设计第二次作业
  • 原文地址:https://www.cnblogs.com/Moon-Face/p/5288212.html
Copyright © 2011-2022 走看看