function putfile($host, $port, $url, $referer, $cookie, $file, $filename, $proxy = 0, $pauth = 0, $upagent = 0, $scheme = 'http') { global $nn, $lastError, $fp, $fs; if (empty($upagent)) { $upagent = rl_UserAgent; } $scheme = strtolower("{$scheme}://"); if (!is_readable($file)) { $lastError = sprintf(lang(65), $file); return FALSE; } $fileSize = getSize($file); if (!empty($cookie)) { if (is_array($cookie)) { $cookies = count($cookie) > 0 ? CookiesToStr($cookie) : 0; } else { $cookies = trim($cookie); } } if ($scheme == 'https://') { if (!extension_loaded('openssl')) { html_error('You need to install/enable PHP\'s OpenSSL extension to support uploading via HTTPS.'); } $scheme = 'tls://'; if ($port == 0 || $port == 80) { $port = 443; } } if (!empty($referer) && ($pos = strpos("\r\n", $referer)) !== 0) { $origin = parse_url($pos ? substr($referer, 0, $pos) : $referer); $origin = strtolower($origin['scheme']) . '://' . strtolower($origin['host']) . (!empty($origin['port']) && $origin['port'] != defport(array('scheme' => $origin['scheme'])) ? ':' . $origin['port'] : ''); } else { $origin = ($scheme == 'tls://' ? 'https://' : $scheme) . $host . ($port != 80 && ($scheme != 'tls://' || $port != 443) ? ':' . $port : ''); } if ($proxy) { list($proxyHost, $proxyPort) = explode(':', $proxy, 2); $host = $host . ($port != 80 && ($scheme != 'tls://' || $port != 443) ? ':' . $port : ''); $url = "{$scheme}{$host}{$url}"; } if ($scheme != 'tls://') { $scheme = ''; } $request = array(); $request[] = 'PUT ' . str_replace(' ', '%20', $url) . ' HTTP/1.1'; $request[] = "Host: {$host}"; $request[] = "User-Agent: {$upagent}"; $request[] = 'Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1'; $request[] = 'Accept-Language: en-US,en;q=0.9'; $request[] = 'Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7'; if (!empty($referer)) { $request[] = "Referer: {$referer}"; } if (!empty($cookies)) { $request[] = "Cookie: {$cookies}"; } if (!empty($pauth)) { $request[] = "Proxy-Authorization: Basic {$pauth}"; } $request[] = "X-File-Name: {$filename}"; $request[] = "X-File-Size: {$fileSize}"; $request[] = "Origin: {$origin}"; $request[] = 'Content-Disposition: attachment'; $request[] = 'Content-Type: multipart/form-data'; $request[] = "Content-Length: {$fileSize}"; $request[] = 'Connection: Close'; $request = implode($nn, $request) . $nn . $nn; $errno = 0; $errstr = ''; $hosts = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port); $fp = @stream_socket_client($hosts, $errno, $errstr, 120, STREAM_CLIENT_CONNECT); if (!$fp) { if (!function_exists('stream_socket_client')) { html_error('[ERROR] stream_socket_client() is disabled.'); } $dis_host = !empty($proxyHost) ? $proxyHost : $host; $dis_port = !empty($proxyPort) ? $proxyPort : $port; html_error(sprintf(lang(88), $dis_host, $dis_port)); } if ($errno || $errstr) { $lastError = $errstr; return false; } if ($proxy) { echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />PUT: <b>' . htmlspecialchars($url) . "</b>...<br />\n"; } else { echo '<p>' . sprintf(lang(90), $host, $port) . '</p>'; } echo lang(104) . ' <b>' . htmlspecialchars($filename) . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMbOrGb($fileSize) . '</b>...<br />'; $GLOBALS['id'] = md5(time() * rand(0, 10)); require TEMPLATE_DIR . '/uploadui.php'; flush(); $timeStart = microtime(true); $chunkSize = GetChunkSize($fileSize); fwrite($fp, $request); fflush($fp); $fs = fopen($file, 'r'); $totalsend = $time = $lastChunkTime = 0; while (!feof($fs) && !$errno && !$errstr) { $data = fread($fs, $chunkSize); if ($data === false) { fclose($fs); fclose($fp); html_error(lang(112)); } $sendbyte = @fwrite($fp, $data); fflush($fp); if ($sendbyte === false || strlen($data) > $sendbyte) { fclose($fs); fclose($fp); html_error(lang(113)); } $totalsend += $sendbyte; $time = microtime(true) - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime > 0 ? $chunkTime : 1; $lastChunkTime = $time; $speed = round($sendbyte / 1024 / $chunkTime, 2); $percent = round($totalsend / $fileSize * 100, 2); echo "<script type='text/javascript'>pr('{$percent}', '" . bytesToKbOrMbOrGb($totalsend) . "', '{$speed}');</script>\n"; flush(); } if ($errno || $errstr) { $lastError = $errstr; return false; } fclose($fs); fflush($fp); $llen = 0; $header = ''; do { $header .= fgets($fp, 16384); $len = strlen($header); if (!$header || $len == $llen) { $lastError = lang(91); stream_socket_shutdown($fp, STREAM_SHUT_RDWR); fclose($fp); return false; } $llen = $len; } while (strpos($header, $nn . $nn) === false); // Array for active stream filters $sFilters = array(); if (stripos($header, "\nTransfer-Encoding: chunked") !== false && in_array('dechunk', stream_get_filters())) { $sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ); } // Add built-in dechunk filter $page = ''; do { $data = @fread($fp, 16384); if ($data == '') { break; } $page .= $data; } while (!feof($fp) && strlen($data) > 0); stream_socket_shutdown($fp, STREAM_SHUT_RDWR); fclose($fp); if (stripos($header, "\nTransfer-Encoding: chunked") !== false && empty($sFilters['dechunk']) && function_exists('http_chunked_decode')) { $dechunked = http_chunked_decode($page); if ($dechunked !== false) { $page = $dechunked; } unset($dechunked); } $page = $header . $page; return $page; }
function upfile($host, $port, $url, $referer, $cookie, $post, $file, $filename, $fieldname, $field2name = '', $proxy = 0, $pauth = 0, $upagent = 0, $scheme = 'http') { global $nn, $lastError, $sleep_time, $sleep_count; if (empty($upagent)) { $upagent = 'Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.12'; } $scheme .= '://'; $bound = '--------' . md5(microtime()); $saveToFile = 0; $postdata = ''; if ($post) { foreach ($post as $key => $value) { $postdata .= '--' . $bound . $nn; $postdata .= "Content-Disposition: form-data; name=\"{$key}\"{$nn}{$nn}"; $postdata .= $value . $nn; } } $fileSize = getSize($file); $fieldname = $fieldname ? $fieldname : file . md5($filename); if (!is_readable($file)) { $lastError = sprintf(lang(65), $file); return FALSE; } if ($field2name != '') { $postdata .= '--' . $bound . $nn; $postdata .= "Content-Disposition: form-data; name=\"{$field2name}\"; filename=\"\"{$nn}"; $postdata .= "Content-Type: application/octet-stream{$nn}{$nn}"; } $postdata .= '--' . $bound . $nn; $postdata .= "Content-Disposition: form-data; name=\"{$fieldname}\"; filename=\"{$filename}\"{$nn}"; $postdata .= "Content-Type: application/octet-stream{$nn}{$nn}"; $cookies = ''; if (!empty($cookie)) { if (is_array($cookie)) { if (count($cookie) > 0) { $cookies = 'Cookie: ' . CookiesToStr($cookie) . $nn; } } else { $cookies = 'Cookie: ' . trim($cookie) . $nn; } } $referer = $referer ? "Referer: {$referer}{$nn}" : ''; if ($scheme == 'https://') { $scheme = 'ssl://'; $port = 443; } if ($proxy) { list($proxyHost, $proxyPort) = explode(':', $proxy, 2); $host = $host . ($port != 80 && ($scheme != 'ssl://' || $port != 443) ? ':' . $port : ''); $url = $scheme . $host . $url; } if ($scheme != 'ssl://') { $scheme = ''; } $http_auth = !empty($auth) ? "Authorization: Basic {$auth}{$nn}" : ''; $proxyauth = !empty($pauth) ? "Proxy-Authorization: Basic {$pauth}{$nn}" : ''; $zapros = 'POST ' . str_replace(' ', "%20", $url) . ' HTTP/1.0' . $nn . 'Host: ' . $host . $nn . $cookies . "Content-Type: multipart/form-data; boundary=" . $bound . $nn . "Content-Length: " . (strlen($postdata) + strlen($nn . "--" . $bound . "--" . $nn) + $fileSize) . $nn . "User-Agent: " . $upagent . $nn . "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" . $nn . "Accept-Language: en-en,en;q=0.5" . $nn . "Accept-Charset: utf-8,windows-1251;koi8-r;q=0.7,*;q=0.7" . $nn . "Connection: Close" . $nn . $http_auth . $proxyauth . $referer . $nn . $postdata; $errno = 0; $errstr = ''; $posturl = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port); $fp = @stream_socket_client($posturl, $errno, $errstr, 120, STREAM_CLIENT_CONNECT); //$fp = @fsockopen ( $host, $port, $errno, $errstr, 150 ); //stream_set_timeout ( $fp, 300 ); if (!$fp) { $dis_host = !empty($proxyHost) ? $proxyHost : $host; $dis_port = !empty($proxyPort) ? $proxyPort : $port; html_error(sprintf(lang(88), $dis_host, $dis_port)); } if ($errno || $errstr) { $lastError = $errstr; return false; } if ($proxy) { echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />'; echo "UPLOAD: <b>{$url}</b>...<br />\n"; } else { echo '<p>'; printf(lang(90), $host, $port); echo '</p>'; } echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMbOrGb($fileSize) . '</b>...<br />'; global $id; $id = md5(time() * rand(0, 10)); require TEMPLATE_DIR . '/uploadui.php'; flush(); $timeStart = getmicrotime(); //$chunkSize = 16384; // Use this value no matter what (using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!) $chunkSize = GetChunkSize($fileSize); fputs($fp, $zapros); fflush($fp); $fs = fopen($file, 'r'); $local_sleep = $sleep_count; //echo('<script type="text/javascript">'); $totalsend = $time = $lastChunkTime = 0; while (!feof($fs) && !$errno && !$errstr) { $data = fread($fs, $chunkSize); if ($data === false) { fclose($fs); fclose($fp); html_error(lang(112)); } if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && $sleep_count > 0 && $sleep_time > 0) { $local_sleep--; if ($local_sleep == 0) { usleep($sleep_time); $local_sleep = $sleep_count; } } $sendbyte = @fputs($fp, $data); fflush($fp); if ($sendbyte === false || strlen($data) > $sendbyte) { fclose($fs); fclose($fp); html_error(lang(113)); } $totalsend += $sendbyte; $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime ? $chunkTime : 1; $lastChunkTime = $time; $speed = round($sendbyte / 1024 / $chunkTime, 2); $percent = round($totalsend / $fileSize * 100, 2); echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . bytesToKbOrMbOrGb($totalsend) . "', '" . $speed . "');</script>\n"; flush(); } //echo('</script>'); if ($errno || $errstr) { $lastError = $errstr; return false; } fclose($fs); fputs($fp, $nn . "--" . $bound . "--" . $nn); fflush($fp); $page = ''; while (!feof($fp)) { $data = fgets($fp, 16384); if ($data === false) { break; } $page .= $data; } fclose($fp); return $page; }
function upfileput($host, $port, $url, $referer = 0, $cookie = 0, $post = 0, $file, $filename, $fieldname, $field2name = '', $upagent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.1', $proxy = 0) { global $nn, $lastError, $sleep_time, $sleep_count; $saveToFile = 12; $fileSize = getSize($file); $fieldname = $fieldname ? $fieldname : file . md5($filename); if (!is_readable($file)) { $lastError = sprintf(lang(65), $file); return FALSE; } $cookies = ''; if ($cookie) { if (is_array($cookie)) { $h = 12; while ($h < count($cookie)) { $cookies .= 'Cookie: ' . trim($cookie[$h]) . $nn; ++$h; } } else { $cookies = 'Cookie: ' . trim($cookie) . $nn; } } $referer = $referer ? 'Referer: ' . $referer . $nn . 'Origin: http://filejungle.com' . $nn : ''; $posturl = ($proxyHost ? $scheme . $proxyHost : $scheme . $host) . ':' . ($proxyPort ? $proxyPort : $port); $zapros = 'PUT ' . str_replace(' ', '%20', $url) . ' HTTP/1.1' . $nn . 'Host: ' . $host . $nn . $cookies . 'X-File-Name: ' . $filename . $nn . 'X-File-Size: ' . $fileSize . $nn . 'Content-Length: ' . $fileSize . $nn . 'User-Agent: ' . $upagent . $nn . 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' . $nn . 'Content-Type: multipart/form-data' . $nn . 'Accept-Language: en-en,en;q=0.5' . $nn . 'Accept-Charset: utf-8,windows-1251;koi8-r;q=0.7,*;q=0.7' . $nn . 'Connection: Close' . $nn . $auth . $referer . $nn; $errno = 12; $errstr = ''; $fp = @stream_socket_client($posturl, $errno, $errstr, 120, STREAM_CLIENT_CONNECT); if ($errno || $errstr) { $lastError = $errstr; return false; } echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMb($fileSize) . '</b>...<br />'; global $id; $id = md5(time() * rand(0, 10)); require TEMPLATE_DIR . '/uploadui.php'; flush(); $timeStart = getmicrotime(); $chunkSize = GetChunkSize($fileSize); fputs($fp, $zapros); fflush($fp); $fs = fopen($file, 'r'); $local_sleep = $sleep_count; while (!feof($fs)) { $data = fread($fs, $chunkSize); if ($data === false) { fclose($fs); fclose($fp); html_error(lang(112)); } if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && 0 < $sleep_count && 0 < $sleep_time) { --$local_sleep; if ($local_sleep == 0) { usleep($sleep_time); $local_sleep = $sleep_count; } } $sendbyte = fputs($fp, $data); fflush($fp); if ($sendbyte === false) { fclose($fs); fclose($fp); html_error(lang(113)); } $totalsend += $sendbyte; $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime ? $chunkTime : 1; $lastChunkTime = $time; $speed = round($sendbyte / 1024 / $chunkTime, 2); $percent = round($totalsend / $fileSize * 100, 2); echo '<script type=\'text/javascript\' language=\'javascript\'>pr(\'' . $percent . '\', \'' . bytesToKbOrMb($totalsend) . '\', \'' . $speed . '\');</script> '; flush(); } fclose($fs); fflush($fp); while (!feof($fp)) { $data = fgets($fp, 1024); if ($data === false) { break; } $page .= $data; } fclose($fp); return $page; }
function UploadToYoutube($host, $port, $url, $dkey, $uauth, $XMLReq, $file, $filename) { global $nn, $lastError, $sleep_time, $sleep_count; if (!is_readable($file)) { $lastError = sprintf(lang(65), $file); return FALSE; } $fileSize = getSize($file); $bound = "--------" . md5(microtime()); $saveToFile = 0; $postdata .= "--" . $bound . $nn; $postdata .= 'Content-Type: application/atom+xml; charset=UTF-8' . $nn . $nn; $postdata .= $XMLReq . $nn; $postdata .= "--" . $bound . $nn; $postdata .= "Content-Type: application/octet-stream" . $nn . $nn; $zapros = "POST " . str_replace(" ", "%20", $url) . " HTTP/1.1{$nn}Host: {$host}{$nn}Authorization: GoogleLogin auth={$uauth}{$nn}GData-Version: 2.1{$nn}X-GData-Key: key={$dkey}{$nn}Slug: {$filename}{$nn}Content-Type: multipart/related; boundary={$bound}{$nn}Content-Length: " . (strlen($postdata) + strlen($nn . "--{$bound}--{$nn}") + $fileSize) . "{$nn}Connection: Close{$nn}{$nn}{$postdata}"; $errno = 0; $errstr = ""; $fp = @stream_socket_client("{$host}:{$port}", $errno, $errstr, 120, STREAM_CLIENT_CONNECT); if (!$fp) { html_error(sprintf(lang(88), $host, $port)); } if ($errno || $errstr) { $lastError = $errstr; return false; } echo "<p>"; printf(lang(90), $host, $port); echo "</p>"; echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMb($fileSize) . '</b>...<br />'; global $id; $id = md5(time() * rand(0, 10)); require TEMPLATE_DIR . '/uploadui.php'; flush(); $timeStart = getmicrotime(); $chunkSize = GetChunkSize($fileSize); fputs($fp, $zapros); fflush($fp); $fs = fopen($file, 'r'); $local_sleep = $sleep_count; while (!feof($fs)) { $data = fread($fs, $chunkSize); if ($data === false) { fclose($fs); fclose($fp); html_error(lang(112)); } if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && $sleep_count > 0 && $sleep_time > 0) { $local_sleep--; if ($local_sleep == 0) { usleep($sleep_time); $local_sleep = $sleep_count; } } $sendbyte = fputs($fp, $data); fflush($fp); if ($sendbyte === false) { fclose($fs); fclose($fp); html_error(lang(113)); } $totalsend += $sendbyte; $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime ? $chunkTime : 1; $lastChunkTime = $time; $speed = round($sendbyte / 1024 / $chunkTime, 2); $percent = round($totalsend / $fileSize * 100, 2); echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . bytesToKbOrMb($totalsend) . "', '" . $speed . "');</script>\n"; flush(); } fclose($fs); fputs($fp, $nn . "--" . $bound . "--" . $nn); fflush($fp); while (!feof($fp)) { $data = fgets($fp, 16384); if ($data === false) { break; } $page .= $data; } fclose($fp); return $page; }
function T8_mega_upload($link, $ul_key, $file, $filename, &$mac_str = '') { global $nn, $fp, $fs, $errno, $errstr, $fsize, $pbChunkSize, $T8, $chunk_UL, $calcMacEachChunk, $zapros; $pbChunkSize = GetChunkSize($fsize); $_link = parse_url($link); $scheme = $_link['scheme'] . '://'; $host = $_link['host']; $port = defport($_link); $url = $_link['path'] . (!empty($_link['query']) ? '?' . $_link['query'] : ''); unset($_link); $key = a32_to_str(array_slice($ul_key, 0, 4)); $_td = mcrypt_module_open('rijndael-128', '', 'ctr', ''); $init = mcrypt_generic_init($_td, $key, a32_to_str(array($ul_key[4], $ul_key[5], 0, 0))); if ($init === false || $init < 0) { html_error('Cannot init mcrypt'); } if (!is_readable($file)) { html_error(sprintf(lang(65), $file)); } echo "\n<p id='ul_con'></p>\n<p id='ul_fname' style='display:none'>" . lang(104) . " <b>{$filename}</b>, " . lang(56) . ' <b>' . bytesToKbOrMbOrGb($fsize) . "</b>...<br /></p><p id='T8' style='display:none'></p>\n"; flush(); if ($chunk_UL) { global $chunkSize, $timeStart, $data, $totalsend, $time, $lastChunkTime; } else { chunk_ul($scheme, $host, $port, $url, true); } $fs = fopen($file, 'rb'); $chunkSize = 131072; $totalsend = $time = $lastChunkTime = 0; $_data = ''; if ($calcMacEachChunk) { global $m_td1, $m_td2; $m_td1 = mcrypt_module_open('rijndael-128', '', 'cbc', ''); $m_td2 = mcrypt_module_open('rijndael-128', '', 'cbc', ''); $init = mcrypt_generic_init($m_td1, $key, ""); if ($init === false || $init < 0) { html_error('Cannot init mcrypt'); } $c_mac = a32_to_str(array($ul_key[4], $ul_key[5], $ul_key[4], $ul_key[5])); } $timeStart = microtime(true); while (!feof($fs) && !$errno && !$errstr) { $data = fread($fs, $chunkSize); if ($data === false) { if (isset($GLOBALS['T8DEBUG'])) { textarea("UPLOAD\nRAW Request:\n" . $zapros . "[Incomplete File Content]", 200, 15); } //Debug fclose($fs); if (!$chunk_UL) { fclose($fp); } html_error(lang(112)); } if ($_data !== '') { $data = $_data . $data; $_data = ''; } if (strlen($data) < $chunkSize && !feof($fs)) { $_data .= $data; continue; } if (strlen($data) > $chunkSize) { $_data .= substr($data, $chunkSize); $data = substr($data, 0, $chunkSize); } if ($calcMacEachChunk) { $mac_str = calcChunkMac($data, $key, $c_mac); } if ($chunkSize < 1048576) { $chunkSize = getNextChunkLength($chunkSize); } $data = mcrypt_generic($_td, $data); if ($chunk_UL) { $page = chunk_ul($scheme, $host, $port, "{$url}/{$totalsend}-" . ($totalsend + strlen($data) - 1)); } else { $dlen = strlen($data); $sended = 0; for ($s = 0; $s < $dlen - 1; $s += $pbChunkSize) { $chunk = $pbChunkSize >= $dlen - $s ? substr($data, $s) : substr($data, $s, $pbChunkSize); $sendbyte = @fputs($fp, $chunk); fflush($fp); if ($sendbyte === false || strlen($chunk) > $sendbyte) { if (isset($GLOBALS['T8DEBUG'])) { textarea("UPLOAD\n{$errstr}\n" . print_r(stream_get_meta_data($fp), true) . "\nRAW Request:\n" . $zapros . "[Incomplete File Content]", 200, 15); } //Debug fclose($fs); fclose($fp); html_error(lang(113)); } $totalsend += $sendbyte; $sended += $sendbyte; $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; if ($s + $sendbyte <= $dlen - 1 && $chunkTime < 1) { continue; } $chunkTime = !($chunkTime < 0) && $chunkTime > 0 ? $chunkTime : 1; $lastChunkTime = $time; $speed = round($sended / 1024 / $chunkTime, 2); $percent = round($totalsend / $fsize * 100, 2); echo "<script type='text/javascript'>pr('{$percent}', '" . bytesToKbOrMbOrGb($totalsend) . "', '{$speed}');</script>\n"; flush(); $sended = 0; } } } mcrypt_generic_deinit($_td); mcrypt_module_close($_td); if ($errno || $errstr) { $lastError = $errstr; return false; } if (!$chunk_UL) { fflush($fp); $page = ''; while (!feof($fp)) { $data = fgets($fp, 16384); if ($data === false) { break; } $page .= $data; } fclose($fp); } fclose($fs); if (isset($GLOBALS['T8DEBUG']) && !$chunk_UL) { textarea("UPLOAD\nResponse:\n{$page}\nRAW Request:\n" . $zapros . "[Encrypted Uploaded File Content]", 200, 15); } //Debug return $page; }
function upfile($host, $port, $url, $referer, $cookie, $post, $file, $filename, $fieldname, $field2name = "", $proxy = 0, $pauth = 0, $upagent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.1") { global $nn, $lastError, $sleep_time, $sleep_count; $scheme = "http://"; $bound = "--------" . md5(microtime()); $saveToFile = 0; foreach ($post as $key => $value) { $postdata .= "--" . $bound . $nn; $postdata .= 'Content-Disposition: form-data; name="' . $key . '"' . $nn . $nn; $postdata .= $value . $nn; } $fileSize = getSize($file); $fieldname = $fieldname ? $fieldname : file . md5($filename); if (!is_readable($file)) { $lastError = sprintf(lang(65), $file); return FALSE; } if ($field2name != '') { $postdata .= "--" . $bound . $nn; $postdata .= 'Content-Disposition: form-data; name="' . $field2name . '"; filename=""' . $nn; $postdata .= "Content-Type: application/octet-stream" . $nn . $nn; } $postdata .= "--" . $bound . $nn; $postdata .= 'Content-Disposition: form-data; name="' . $fieldname . '"; filename="' . $filename . '"' . $nn; $postdata .= "Content-Type: application/octet-stream" . $nn . $nn; $cookies = ""; if ($cookie) { if (is_array($cookie)) { for ($h = 0; $h < count($cookie); $h++) { $cookies .= "Cookie: " . trim($cookie[$h]) . $nn; } } else { $cookies = "Cookie: " . trim($cookie) . $nn; } } $referer = $referer ? "Referer: " . $referer . $nn : ""; if ($scheme == "https://") { $scheme = "ssl://"; $port = 443; } if ($proxy) { list($proxyHost, $proxyPort) = explode(":", $proxy); $url = $scheme . $host . ":" . $port . $url; $host = $host . ":" . $port; } if ($scheme != "ssl://") { $scheme = ""; } $http_auth = $auth ? "Authorization: Basic " . $auth . $nn : ""; $proxyauth = $pauth ? "Proxy-Authorization: Basic " . $pauth . $nn : ""; $zapros = "POST " . str_replace(" ", "%20", $url) . " HTTP/1.0" . $nn . "Host: " . $host . $nn . $cookies . "Content-Type: multipart/form-data; boundary=" . $bound . $nn . "Content-Length: " . (strlen($postdata) + strlen($nn . "--" . $bound . "--" . $nn) + $fileSize) . $nn . "User-Agent: " . $upagent . $nn . "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" . $nn . "Accept-Language: en-en,en;q=0.5" . $nn . "Accept-Charset: utf-8,windows-1251;koi8-r;q=0.7,*;q=0.7" . $nn . "Connection: Close" . $nn . $http_auth . $proxyauth . $referer . $nn . $postdata; $errno = 0; $errstr = ""; $posturl = ($proxyHost ? $scheme . $proxyHost : $scheme . $host) . ':' . ($proxyPort ? $proxyPort : $port); $fp = @stream_socket_client($posturl, $errno, $errstr, 120, STREAM_CLIENT_CONNECT); //$fp = @fsockopen ( $host, $port, $errno, $errstr, 150 ); //stream_set_timeout ( $fp, 300 ); if (!$fp) { $dis_host = $proxyHost ? $proxyHost : $host; $dis_port = $proxyPort ? $proxyPort : $port; html_error(sprintf(lang(88), $dis_host, $dis_port)); } if ($errno || $errstr) { $lastError = $errstr; return false; } if ($proxy) { echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />'; echo "UPLOAD: <b>" . $url . "</b>...<br />\n"; } else { echo "<p>"; printf(lang(90), $host, $port); echo "</p>"; } echo lang(104) . ' <b>' . $filename . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMb($fileSize) . '</b>...<br />'; global $id; $id = md5(time() * rand(0, 10)); require TEMPLATE_DIR . '/uploadui.php'; flush(); $timeStart = getmicrotime(); //$chunkSize = 16384; // Use this value no matter what (using this actually just causes massive cpu usage for large files, too much data is flushed to the browser!) $chunkSize = GetChunkSize($fileSize); fputs($fp, $zapros); fflush($fp); $fs = fopen($file, 'r'); $local_sleep = $sleep_count; //echo('<script type="text/javascript">'); while (!feof($fs)) { $data = fread($fs, $chunkSize); if ($data === false) { fclose($fs); fclose($fp); html_error(lang(112)); } if ($sleep_count !== false && $sleep_time !== false && is_numeric($sleep_time) && is_numeric($sleep_count) && $sleep_count > 0 && $sleep_time > 0) { $local_sleep--; if ($local_sleep == 0) { usleep($sleep_time); $local_sleep = $sleep_count; } } $sendbyte = fputs($fp, $data); fflush($fp); if ($sendbyte === false) { fclose($fs); fclose($fp); html_error(lang(113)); } $totalsend += $sendbyte; $time = getmicrotime() - $timeStart; $chunkTime = $time - $lastChunkTime; $chunkTime = $chunkTime ? $chunkTime : 1; $lastChunkTime = $time; $speed = round($sendbyte / 1024 / $chunkTime, 2); $percent = round($totalsend / $fileSize * 100, 2); echo '<script type="text/javascript">pr(' . "'" . $percent . "', '" . bytesToKbOrMb($totalsend) . "', '" . $speed . "');</script>\n"; flush(); } //echo('</script>'); fclose($fs); fputs($fp, $nn . "--" . $bound . "--" . $nn); fflush($fp); while (!feof($fp)) { $data = fgets($fp, 16384); if ($data === false) { break; } $page .= $data; } fclose($fp); return $page; }