这是一个适用于 php7.3 但不适用于 php7.4 的示例。
卷曲.php
$file='test.txt';
$cfile=curl_file_create($file, mime_content_type($file), 'test.txt');
$post=array('file'=>$cfile);
$ch=curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, 'https://example.com/curl-upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response=curl_exec($ch);
print_r(curl_getinfo($ch));
print_r($response);
if (curl_errno($ch)) {
var_dump(curl_errno($ch));
}
卷曲上传.php
echo 'upload';
print_r($_FILES);
$file=file_get_contents('php://input');
print_r($file);
知道为什么吗?
非常感谢!