函数名:CURLFile::__construct()
适用版本:PHP 5 >= 5.5.0, PHP 7
用法:CURLFile::__construct() 函数用于在用于上传文件时创建一个新的CURLFile对象。
语法:public CURLFile::__construct ( string $filename [, string $mimetype [, string $postname ]] )
参数:
返回值:无返回值。
示例:
// 创建CURLFile对象
$file = new CURLFile('path/to/file.txt', 'text/plain', 'my_file.txt');
// 将CURLFile对象添加到POST请求中
$postData = array('file' => $file);
// 发起cURL请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/upload.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
curl_close($ch);
注意事项: