问题
So due to Cloudflare's limitations of 250MB I am trying to circumvent around it through Chunked encoding which is supposed to upload the files in chunks that way I don't get the 413 Request Entity Too Large
so I followed the general idea of this.
https://github.com/php-curl-class/php-curl-class/issues/369
And it is still returning this error, but I don't know how to properly verify the headers that it's chunked and maybe I'm just messing up something?
$stream = fopen($getFile, 'r');
// Create a curl handle to upload to the file server
$ch = curl_init($getServer . '/Upload?server=' . $getOldest['vt_server'] . '&video=' . $getOldest['v_key'] . '&type=' . $getOldest['vt_filetype']);
// Send a PUT request
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
// Let curl know that we are sending an entity body
curl_setopt($ch, CURLOPT_UPLOAD, true);
// Let curl know that we are using a chunked transfer encoding
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Transfer-Encoding: chunked'));
// Use a callback to provide curl with data to transmit from the stream
curl_setopt($ch, CURLOPT_READFUNCTION, function($ch, $fd, $length) use ($stream) {
return fread($stream, 1024);
});
curl_exec($ch);
curl_close($ch);
Just to add a little bit more information, there's another part of the code where the user uploads it through a form and then with JS / PHP it can do chunk uploading which helps me bypass Cloudflare's limits, it's the other way around that it doesn't properly work the way it should.
$putdata = fopen("php://input", "r");
$fp = fopen($path['videos'] . '/' . $_GET['video'] . '.' . $_GET['type'], "w");
while ($data = fread($putdata, 1024 * 1024))
fwrite($fp, $data);
fclose($fp);
fclose($putdata);
Added code for how the data is read / written.
UPDATE: I did try contacting Cloudflare regarding HTTP chunked transferring and if it is possible and they didn't really give me a specific answer besides advertising their "Cloudflare Streaming" platform. And I'm still struggling on this issue, anyone know much about Cloudflare's upload limit and chunked uploading with it?
来源:https://stackoverflow.com/questions/50921576/php-curl-chunked-encoding-a-large-file-700mb