_header); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING , "gzip"); if($proxy !== false) curl_setopt($ch, CURLOPT_PROXY , $proxy); if($referer !== false) curl_setopt($ch, CURLOPT_REFERER, $referer); if($post !== false) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } if(is_array($this->_cookies)) { $cookies = ''; foreach($this->_cookies as $key => $val) { $cookies .= $key.'='.$val.'; '; } curl_setopt($ch, CURLOPT_COOKIE, $cookies); } $body = curl_exec($ch); preg_match_all("/Set-Cookie: (.*?)=(.*?);/i", $body, $res); foreach($res[1] as $key => $value) { $this->_cookies[$value] = $res[2][$key]; } curl_close($ch); return $body; } public function letibitUrl($file, $path) { $body = $this->getUrl('http://178.165.70.10/curl.php?url=http://www.twirpx.com/file/'.$file['twirpx_id'].'/'); preg_match("/href=\"\/heap\/(.*)\/\">/", $body, $heap); $body = $this->getUrl('http://178.165.70.10/curl.php?url=http://www.twirpx.com/heap/'.$heap[1].'/'); if(strpos($body, 'letitbit.net')) { preg_match("/Location:(.*)\n/", $body, $location); return trim($location[1]); } else return false; } public function letitbitApi($r) { $ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, 'http://api.letitbit.net/json'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array('r' => json_encode(array('gfQmqz9ip', $r)))); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($ch); curl_close($ch); return $content; } public function download($file, $path) { //if($_GET['test'] == 1) { $row = Application::app()->db()->select('my_url, status')->from('letitbit_urls')->where("hash = '".$file['hash']."'")->limit(1)->execute('getRow'); if(!empty($file['letibit_url'])) { $row['my_url'] = $file['letibit_url']; } if(!empty($row['my_url'])) { //$link = $this->letibitUrl($file, $path); $link = $row['my_url']; if($link !== false) { $response = $this->letitbitApi(array("download/direct_links", array('link' => $link, "pass"=>"awmp8529ja"))); $response = json_decode($response, true); /*if(empty($response['data'][0][0]) && !$isFileHash) { $response = $this->letitbitApi(array("download/direct_links", array('link' => $file['letibit_url'], "pass"=>"awmp8529ja"))); $response = json_decode($response, true); }*/ $url = $response['data'][0][0]; if($response['status'] == 'OK' && !empty($url)) { $key_name = 'letitbit_file_download'; $key = Application::app()->db()->select('`key`')->from('stats')->where("`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'")->limit(1)->execute('getField'); if(empty($key)) { Application::app()->db()->insert('stats', array('`key`' => $key_name,'value' => '1','date' => date("Y-m-d", time()))); } else { Application::app()->db()->update('stats', array('value' => "value + 1"), "`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'", false); } //------------ $parse = parse_url($url); $socket = @fsockopen($parse['host'], "80", $errno, $errstr, 5); $request = "GET ".$url." HTTP/1.1"."\r\n". "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0\r\n". "Host: ".$parse['host']."\r\n". "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n". "Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3\r\n". "Accept-Encoding: gzip, deflate\r\n". "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7\r\n". "Connection: keep-alive\r\n\r\n"; @fwrite($socket, $request); $head = ""; $content = ""; while($socket !== false && ($head != "\r\n") && !@feof($socket)) { $head = @fgets($socket, 2048); $content .= $head; } $ext = Func::fileExt(Func::cutStr($content, "Content-Disposition:", "\n")); $file_size = Func::cutStr($content, "Content-Length:", "\n"); $name = Func::sefUrl($file['title']).'_'.$file['hash'].'.'.$ext; $type = Func::cutStr($content, "Content-Type:", "\n"); $modif = Func::cutStr($content, "Last-Modified:", "\n"); if(!is_numeric($file_size) || $file_size <= 0) { $key_name = 'letitbit_download_error'; $key = Application::app()->db()->select('`key`')->from('stats')->where("`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'")->limit(1)->execute('getField'); if(empty($key)) { Application::app()->db()->insert('stats', array('`key`' => $key_name,'value' => '1','date' => date("Y-m-d", time()))); } else { Application::app()->db()->update('stats', array('value' => "value + 1"), "`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'", false); } die('Файл "'.$file['title'].'" временно недоступен для скачивания.

Приносим свои извенения.'); } Func::checkDir($path); header("Content-type: ".$type); header("Content-Length: ".$file_size); header('Content-Disposition: attachment; filename='.$name); header('Accept-Ranges: bytes'); $size=0; flush(); ob_flush(); if($socket) { $handle = fopen(dirname($path).'/'.$name, 'w'); while(!feof($socket) && !connection_status()){ $block = fgets($socket, 1024); fwrite($handle, $block); echo $block; flush(); ob_flush(); $size += strlen($block); if($size == $file_size) { Application::app()->db()->update('files', array('file' => "Y", 'folder' => 2), "hash = '".$file['hash']."'"); break; } } fclose($handle); } else { die('Downloading error...'); } if($size == $file_size) { file_put_contents($path, $name.''.$type); Application::app()->db()->update('files', array('file' => "Y", 'folder' => 2), "hash = '".$file['hash']."'"); } //------------ } else { $key_name = 'letitbit_response_error'; $key = Application::app()->db()->select('`key`')->from('stats')->where("`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'")->limit(1)->execute('getField'); if(empty($key)) { Application::app()->db()->insert('stats', array('`key`' => $key_name,'value' => '1','date' => date("Y-m-d", time()))); } else { Application::app()->db()->update('stats', array('value' => "value + 1"), "`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'", false); } die('Файл "'.$file['title'].'" временно недоступен для скачивания.

Приносим свои извенения.'); } } else { $key_name = 'twirpx_response_error'; $key = Application::app()->db()->select('`key`')->from('stats')->where("`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'")->limit(1)->execute('getField'); if(empty($key)) { Application::app()->db()->insert('stats', array('`key`' => $key_name,'value' => '1','date' => date("Y-m-d", time()))); } else { Application::app()->db()->update('stats', array('value' => "value + 1"), "`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'", false); } die('Файл "'.$file['title'].'" временно недоступен для скачивания.

Приносим свои извенения.'); } } else { $key_name = 'file_not_found'; $key = Application::app()->db()->select('`key`')->from('stats')->where("`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'")->limit(1)->execute('getField'); if(empty($key)) { Application::app()->db()->insert('stats', array('`key`' => $key_name,'value' => '1','date' => date("Y-m-d", time()))); } else { Application::app()->db()->update('stats', array('value' => "value + 1"), "`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'", false); } die('Файл "'.$file['title'].'" временно недоступен для скачивания.

Приносим свои извенения.'); /*$key_name = 'letitbit_our_download'; $key = Application::app()->db()->select('`key`')->from('stats')->where("`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'")->limit(1)->execute('getField'); if(empty($key)) { Application::app()->db()->insert('stats', array('`key`' => $key_name,'value' => '1','date' => date("Y-m-d", time()))); } else { Application::app()->db()->update('stats', array('value' => "value + 1"), "`key` = '".$key_name."' AND date = '".date("Y-m-d", time())."'", false); } header('Location: '.$row['my_url']); die;*/ } //} } public function send($file, $path) { $arr = explode('', file_get_contents($path)); $file = dirname($path).'/'.$arr[0]; $file = str_replace('/var/www/studmedru/data/www/studmed.ru', '', $file); header("Content-type: ".$arr[1]); header('Content-Disposition: attachment; filename=Studmed.ru_'.$arr[0]); header("X-Accel-Redirect: ".$file); die; } public function pathHash($hash, $level=5) { $str = ''; $amp = ''; for($c=0; $c<$level; $c++) { $str .= $amp.substr($hash, $c, 1); $amp = '/'; } return $str; } } ?>