(PHP 8 >= 8.1.0)
CURLStringFile::__construct — 創(chuàng)建 CURLStringFile 對象
$data, string $postname, string $mime = "application/octet-stream")
創(chuàng)建 CURLStringFile 對象,使用 CURLOPT_POSTFIELDS 選項上傳文件。
data待上傳的內(nèi)容。
postname上傳數(shù)據(jù)中的文件名稱。
mime
文件的 MIME 類型(默認(rèn)為 application/octet-stream)。
返回 CURLStringFile 對象。
示例 #1 CURLStringFile::__construct() 示例
<?php
/* http://example.com/upload.php:
<?php
var_dump($_FILES);
var_dump(file_get_contents($_FILES['test_string']['tmp_name']));
?>
*/
// 創(chuàng)建一個 cURL 句柄
$ch = curl_init('http://example.com/upload.php');
// 創(chuàng)建一個 CURLStringFile 對象
$cstringfile = new CURLStringFile('test upload contents','test.txt','text/plain');
// 指定 POST 內(nèi)容
$data = array('test_string' => $cstringfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// 執(zhí)行句柄
curl_exec($ch);
?>
以上例程會輸出:
array(1) {
["test_string"]=>
array(5) {
["name"]=>
string(8) "test.txt"
["type"]=>
string(10) "text/plain"
["tmp_name"]=>
string(14) "/tmp/phpTtaoCz"
["error"]=>
int(0)
["size"]=>
int(20)
}
}
string(20) "test upload contents"