View file load/download.php

File size: 4.46Kb
<?
Error_Reporting(E_ALL & ~E_NOTICE);
include("func.php");
include("set.php");
include("start.php");

if(is_file("$dir_load/$did/$fid"))
{
  if($on_sec_key)
  {
    if($code!="" && file_exists("$dir_temp/$code.lc"))
    {
      $fp=@file_get_contents("$dir_temp/$code.lc");
      $fp=@explode("|",$fp);
      if(time()-$fp[2]<=$set_code_time) $pcode=$fp[1]; else $pcode=0;
      @unlink("$dir_temp/$code.lc");
    } else $pcode="error"; 
    if($kod!=$pcode || $pcode=="error") { header("Location: error.php?id=load_code&did=$did&fid=$fid&pg=$pg"); exit; }
  }
  
  if(!isSet($_COOKIE['mobile'])) { header("Location: info.php?did=$did&fid=$fid&pg=$pg"); exit; } 
  
  $did=str_replace(chr(92),"/",$did);
  $nd=str_replace("/","_!+!_",$did);
  $rsh=rsh($fid);
  $size=@filesize("$dir_load/$did/$fid");
  
  if($f=fopen("$dir_system/$nd-+-$fid.dat","a+"))
  {
    $fb=file_get_contents("$dir_system/$nd-+-$fid.dat");
    $fd=explode("|",$fb);
    if(!isSet($fd[1])) $fd[1]=0;
    if(!isSet($fd[2])) $fd[2]=0;
    if(!isSet($fd[3])) $fd[3]=0;
    $fd[1]++;
    flock($f,LOCK_EX);
    ftruncate($f,0);
    fwrite($f,"|$fd[1]|$fd[2]|$fd[3]|");
    flock($f,LOCK_UN);
    fclose($f);
  }
  
  if($rsh=="jar" && $jad=="on") 
  {
    require_once("modul/pclzip.php");
    $session=md5(time().rand_id(12));
    mkdir("$dir_rubbish/$session/",0777);
    $zip=new PclZip("$dir_load/$did/$fid");
    if ($zip->extract(PCLZIP_OPT_PATH,"$dir_rubbish/$session/")==0) $jad="off";
    else
    {
      rename("$dir_rubbish/$session/META-INF/MANIFEST.MF","$dir_rubbish/$session/load.jad");
      chmod("$dir_rubbish/$session/load.jad",0777);
      if($fjad=fopen("$dir_rubbish/$session/load.jad","a+"))
      {
        fwrite($fjad,"MIDlet-Jar-Size: $size\r\n");
        fwrite($fjad,"MIDlet-Jar-URL: $fid\r\n");
        fwrite($fjad,"Nokia-MIDlet-Category: Game\r\n");
        fclose($fjad);
      }
    }
  }
  
  if($on_sec_load)
  {
    $time=time();
    $ip=$_SERVER['REMOTE_ADDR'];
    $ip_m=explode(".",$ip);
    $ips="$ip_m[0].$ip_m[1]";
    $rand=md5(time().rand_id(12));
    $rdir="$dir_cache/$rand";
    if(mkdir($rdir))
    {
      chmod("$rdir",0777);
      $fht=fopen("$rdir/.htaccess","w+");
      fwrite($fht,"Order Deny,Allow\r\nDeny from all\r\nAllow from $ip");
      fclose($fht);
      chmod("$rdir/.htaccess",0777);
      $fct=fopen("$rdir/file.dat","w+");
      fwrite($fct,"|$time|$ip|");
      fclose($fct);
      if($rsh=="jar" && $jad=="on")
      {
        @copy("$dir_rubbish/$session/load.jad","$rdir/load.jad");
        @chmod("$rdir/load.jad",0777);
        @del_files("$dir_rubbish/$session/");
        @rmdir("$dir_rubbish/$session/");
        if(copy("$dir_load/$did/$fid","$rdir/$fid"))
        {
          chmod("$rdir/$fid",0777);
          Header("Location: $rdir/load.jad");
        } else Header("Location: error.php?id=sec_error"); 
      }
      else
      {
        if(copy("$dir_load/$did/$fid","$rdir/$fid"))
        {
          chmod("$rdir/$fid",0777);
          if($rsh=="jpg" || $rsh=="png" || $rsh=="jpeg")
          {
            $data_img = base64_encode(file_get_contents("$rdir/$fid"));
            $data_img = base64_decode($data_img);
            $img=imageCreateFromString($data_img);
            $w=ImageSX($img);
            $h=ImageSY($img);
            if($w<=96) $r=8;
            elseif($w>96 && $w<101) $r=8;
            elseif($w>=101 && $w<128) $r=9;
            elseif($w>=128 && $w<176) $r=10;
            elseif($w>=176 && $w<240) $r=11;
            elseif($w>=240 && $w<320) $r=12;
            elseif($w>=320) $r=15;
            $color=imagecolorallocate($img,$set_copr_color[0],$set_copr_color[1],$set_copr_color[2]);
            $mark=imageCreateFromPNG("img/marker.png");
            $mx=ImageSX($mark);
            $my=ImageSY($mark);
            if($on_marker) imageCopy($img,$mark,0,0,0,0,$mx,$my); else imagettftext($img, $r, 0, 2, $h-5, $color, "img/comicbd.ttf","$set_copr");
            if($rsh=='png') { imagePNG($img,"$rdir/$fid"); }
            if($rsh=='jpg') { imageJPEG($img,"$rdir/$fid"); }
            chmod("$rdir/$fid",0777);
            imageDestroy($img);
          }
          Header("Location: $rdir/$fid");
        }
        else Header("Location: error.php?id=sec_error");
      }
    } else Header("Location: error.php?id=sec_mkdir");
    exit;
  }
  
  Header("Location: $dir_load/$did/$fid");
}
else
{
  Header("Location: error.php?id=404");
}
?>