略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: curl_file_create

2024-11-13

curl_file_create

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

curl_file_create创建一个 CURLFile 对象

说明

此函数是该函数的别名: CURLFile::__construct()

add a noteadd a note

User Contributed Notes 1 note

up
-2
dk00272 at gmail dot com
1 year ago
function uploadFile($name,$i=0){

        $postField = array();
        $tmpfile = $_FILES[$name]['tmp_name'][$i];
        $filename = basename($_FILES[$name]['name'][$i]);
        $postField['files'] =  curl_file_create($tmpfile, $_FILES[$name]['type'][$i], $filename);
        $headers = array("Content-Type" => "multipart/form-data");
        $curl_handle = curl_init();
        curl_setopt($curl_handle, CURLOPT_URL, 'Put here curl API');

        curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl_handle, CURLOPT_POST, TRUE);
        curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $postField);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
        $returned_fileName = curl_exec($curl_handle);
        curl_close($curl_handle);
        return json_decode($returned_fileName);
    }

官方地址:https://www.php.net/manual/en/function.curl-file-create.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3