<?php
error_reporting(0); 
if($_POST){
header("Access-Control-Allow-origin:*");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include("../config/ht.php");
if ($gb=='0'){
$code=$_SERVER["REQUEST_URI"];
$html ='<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
$html.='<html><head>';
$html.='<meta charset="gb2312">';
$html.='<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />';
$html.='<title>404 Not Found</title>';
$html.='</head><body>';
$html.='<h1>Not Found</h1>';
$html.='<p>The requested URL '.$code.' was not found on this server.</p>';
$html.='</body>';
$html.='</html>';
echo $html;
exit;
}
if ($shipin=='0'){
$code=$_SERVER["REQUEST_URI"];
$html ='<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
$html.='<html><head>';
$html.='<meta charset="gb2312">';
$html.='<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />';
$html.='<title>404 Not Found</title>';
$html.='</head><body>';
$html.='<h1>Not Found</h1>';
$html.='<p>The requested URL '.$code.' was not found on this server.</p>';
$html.='</body>';
$html.='</html>';
echo $html;
exit;
}
$shipinname=ubo(iconv("UTF-8","gbk",$_POST[shipinname]));
$userid=ubo($_POST[userid]);
$money=ubo($_POST[price]);
$sj=ubo($_POST[priceMin]);
$zykey=ubo($_POST[zykey]);
$tuijian=ubo($_POST[tuijian]);
$fl=ubo($_POST[fl]);
if (strpos($_REQUEST["name"],'php')!== false){exit;}
$houzhui= substr($_REQUEST["name"], strrpos($_REQUEST["name"], '.'));
if($houzhui=='.mp4'){
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){exit;}
if ( !empty($_REQUEST[ 'debug' ]) ){$random = rand(0, intval($_REQUEST[ 'debug' ]) );
if ( $random === 0 ){header("HTTP/1.0 500 Internal Server Error");exit;}}
@set_time_limit(5 * 60);
$shipintmp = '../shipintmp';
$shipin = '../dlsp';
$shipint = true; 
$maxFile = 5 * 3600;
if (!file_exists($shipintmp)) {
@mkdir($shipintmp);
}
if (!file_exists($shipin)) {
@mkdir($shipin);
}
if (isset($_REQUEST["name"])) {
$fileName = $zykey.base64_encode(md5($_REQUEST[name]));
} elseif (!empty($_FILES)) {
$fileName =$zykey.base64_encode(md5($_FILES["file"]["name"]));
} else {
$fileName =$zykey.uniqid("file_");
}
$filePath = $shipintmp . DIRECTORY_SEPARATOR . $fileName;
$uploadPath = $shipin . "/" . md5($fileName).$houzhui;
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 1;
if ($shipint) {
if (!is_dir($shipintmp) || !$dir = opendir($shipintmp)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
}
while (($file = readdir($dir)) !== false) {
$tmpfilePath = $shipintmp . DIRECTORY_SEPARATOR . $file;
if ($tmpfilePath == "{$filePath}_{$chunk}.part" || $tmpfilePath == "{$filePath}_{$chunk}.parttmp") {
continue;
}
if (preg_match('/\.(part|parttmp)$/', $file) && (@filemtime($tmpfilePath) < time() - $maxFile)) {
@unlink($tmpfilePath);
}
}
closedir($dir);
}
if (!$out = @fopen("{$filePath}_{$chunk}.parttmp", "wb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
if (!empty($_FILES)) {
if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
}
if (!$inyhsfu = @fopen($_FILES["file"]["tmp_name"], "rb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
}
} else {
if (!$inyhsfu = @fopen("php://input", "rb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
}
}
while ($buff = fread($inyhsfu, 4096)) {
fwrite($out, $buff);
}
@fclose($out);
@fclose($inyhsfu);
rename("{$filePath}_{$chunk}.parttmp", "{$filePath}_{$chunk}.part");
$inyhsfudex = 0;
$done = true;
for( $inyhsfudex = 0; $inyhsfudex < $chunks; $inyhsfudex++ ) {
if ( !file_exists("{$filePath}_{$inyhsfudex}.part") ) {
$done = false;
break;
}
}
if ( $done ) {
if (!$out = @fopen($uploadPath, "wb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
if ( flock($out, LOCK_EX) ) {
for( $inyhsfudex = 0; $inyhsfudex < $chunks; $inyhsfudex++ ) {
if (!$inyhsfu = @fopen("{$filePath}_{$inyhsfudex}.part", "rb")) {
break;
}
while ($buff = fread($inyhsfu, 4096)) {
fwrite($out, $buff);
}
@fclose($inyhsfu);
@unlink("{$filePath}_{$inyhsfudex}.part");
}
flock($out, LOCK_UN);
}
@fclose($out);
//Ð´ÈëÊý¾Ý¿â
$type="where userid='$userid'";
$user=queryall(user,$type);
if (strpos($uploadPath, '../') !== false) {
$uploadPath= str_replace('../','',$uploadPath);
}
if($user){
$ddhtz=md5($zykey);
$ddhtzds=substr($ddhtz,0,10);
$longdsu='http://'.$url."/wx".random($size)."/".$zykey.$ddhtzds.'ubodl';
$longdsujfh=urlencode($longdsu);
$linkfhu =dwz($longdsujfh,$dwzjk);   
$type="order by id DESC limit 0,1";
$shipin=queryall(daili,$type);
if ($shipin['id']==null){
$shipinid="1";
}else{
$shipinid=$shipin['id']+1;
}
if($sh=='1'){
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `zt`, `shijian`, `spid`, `link`, `lei`, `pic`, `lx`, `flid`) VALUES ('$shipinid','$money','$sj','0','$uploadPath','$userid','$shipinname','$zykey','´ýÉóºË','$shijian','','$linkfhu','','','$tuijian','$fl')"; 
dbinsert(daili,$type);
}else{
$type="(`id`, `money`, `sj`, `cs`, `url`, `userid`, `name`, `zykey`, `zt`, `shijian`, `spid`, `link`, `lei`, `pic`, `lx`, `flid`) VALUES ('$shipinid','$money','$sj','0','$uploadPath','$userid','$shipinname','$zykey','ÒÑÉóºË','$shijian','','$linkfhu','','','$tuijian','$fl')"; 
dbinsert(daili,$type);
$lujing="../peizhi/dl/".$zykey.".txt";
$neir =$shipinid."|ubo|".$userid."|ubo|".$sj."|ubo|".$money."|ubo|"."0";
writefile($lujing,$neir);
}
}
}
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
}
}else{
$code=$_SERVER["REQUEST_URI"];
$html ='<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
$html.='<html><head>';
$html.='<meta charset="gb2312">';
$html.='<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />';
$html.='<title>404 Not Found</title>';
$html.='</head><body>';
$html.='<h1>Not Found</h1>';
$html.='<p>The requested URL '.$code.' was not found on this server.</p>';
$html.='</body>';
$html.='</html>';
echo $html;
exit;
}