Skip to content

Instantly share code, notes, and snippets.

@nextend
Created October 12, 2021 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nextend/2819c93635c5f1c68c13cf1e28a2ef19 to your computer and use it in GitHub Desktop.
Save nextend/2819c93635c5f1c68c13cf1e28a2ef19 to your computer and use it in GitHub Desktop.
<?php
class Test {
protected $handle;
protected $stream_handle;
private $chunkIndex = 0;
public function __construct() {
$url = "*****";
$this->stream_handle = fopen(dirname(__FILE__) . '/test.zip', 'wb');
$this->handle = curl_init($url);
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(
$this,
'stream_body'
));
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, 1160);
curl_exec($this->handle);
curl_close($this->handle);
fclose($this->stream_handle);
$md5 = md5(file_get_contents(dirname(__FILE__) . '/test.zip'));
if ($md5 !== '231732259d67fe83ed6fc02d7ad9be57') {
echo "<h1>Error, not valid md5</h1>";
}
echo "<h1>" . $md5 . "</h1>";
}
public function stream_body($handle, $data) {
$data_length = strlen($data);
fwrite($this->stream_handle, $data);
echo 'Chunk #' . ($this->chunkIndex++) . ': ' . md5($data) . '<br>';
return $data_length;
}
}
new Test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment