- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
<?php
function real_parse_headers($data) {
    $result = [];
    foreach($data as $line) {
        $parts = explode(':', $line, 2);
        if(!isset($parts[1])) continue;
        $key = trim($parts[0]);
        $key = implode('-', array_map(function($value) {return ucfirst($value);}, explode('-', $key)));
        $result[$key] = trim($parts[1]);
    }
    return $result;
}
function real_length($from, $original_context = null) {
    $context = stream_context_create(isset($original_context) ? stream_context_get_options($original_context) : null);
    stream_context_set_option($context, 'http', 'method', 'HEAD');
    @file_get_contents($from, false, $context);
    return intval(real_parse_headers($http_response_header)['Content-Length']);
}
function real_copy($from, string $to, $context = null) {
    define('BLOCK', 8192);
    $total = real_length($from, $context);
    if(!isset($context)) {
        $context = stream_context_create();
    }
    $headers = stream_context_get_options($context)['http']['header'] ?? [];
    stream_context_set_option($context, 'http', 'timeout', '1.0');
    stream_context_set_option($context, 'http', 'ignore_errors', true);
    for($start = 0; $start < $total; $start += $length) {
        $end = $start + BLOCK;
        stream_context_set_option($context, 'http', 'header', array_merge($headers, ["Range: bytes=$start-$end"]));
        $part = @file_get_contents($from, false, $context);
        if($part === false) break;
        $length = strlen($part);
        file_put_contents($to, $part, FILE_APPEND);
    }
}
/* The real example */
$context = stream_context_create([
    'http' => ['method' => 'GET'],
    'ssl'  => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, 'SNI_enabled' => true]
]);        
real_copy('https://govnokod.ru/files/images/pony.jpg', 'pony.jpg', $context);
                                     
        
            Дрочилка для скачивания файлов с сайтов, расположенных за «Cloudflare». Теперь банановая и на «PHP»!