WebDAV filestream upload

Hello there,

i trying to upload file to a nextcloud server with CURL in PHP, but i always get this error:

CURL error (65): necessary data rewind wasn’t possible

Here is the code:

$path = “path_to_file”;
$file = fopen($path, “r”);
$ch = curl_init();

curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => false,
CURLOPT_USERAGENT => “sabre-dav/4.1.5 (http://sabre.io/)”,
CURLOPT_HEADER => true,
CURLOPT_HTTPAUTH => 3,
CURLOPT_USERPWD => “user:password”,
CURLOPT_PUT => true,
CURLOPT_INFILE => $file,
CURLOPT_CUSTOMREQUEST => “PUT”,
CURLOPT_HTTPHEADER => ,
CURLOPT_URL => $nextcloudPath,
CURLOPT_PROTOCOLS => 3,
CURLOPT_REDIR_PROTOCOLS => 3
]);

var_dump(curl_exec ($ch), curl_errno($ch), curl_error($ch));
fclose($file);

What’s missing? The curl config is wrong or something is bad at the nextcloud server?

Please help! Thank you!

Here is the header array:

[
“Content-Type” => $mimeType,
“Content-Length” => filesize($path)
]