<?

include("const.php");



If ($shopcnt <> "") {



 $fcnt = @file("shopcounts.inc");

 for ($i = 0; $i < count($fcnt); $i++) {

  $ar = explode("^", trim($fcnt[$i]));

  If ($ar[0] == $shopcnt) {

   $fid = $i;

   break;

  }

 }

 

 If ($fid >= 0 and $ar[6] == $wm and $ar[4] == "1") {



  $tovid = $ar[7];

  $fgood = @file("goods/$tovid");

  $ar2 = explode("|", trim($fgood[10]));



  $pos = -1;

  $d3 = dir("files/");

  while($text = $d3->read()) {

   If ($text <> "." and $text <> ".." and $text <> ".htaccess") {

    $as = explode(".", $text);

    If ((integer) $as[1] > $pos and $as[0] == $tovid) {

     $pos = (integer) $as[1];

    }

   }

  }

  $d3->close();



  If (trim($fgood[14]) == "0") {

   $ftxt = "files/purchased.{$shopcnt}";

  }

  Else {

   $ftxt = "files/{$tovid}.{$pos}";

  }



  $f=fopen($ftxt,"r");

  header("Content-Type: application/x-zip-compressed");

  header("Content-Disposition: attachment; filename=" . $ar[9]);

  fpassthru($f);

  fclose($f);

 }

 Else {

  echo "<script> alert('Вы пытаетесь получить доступ к неоплаченному Вами товару!'); history.back(); </script>"; 

 }

}

else {

 echo "<script> alert('Вы пытаетесь получить доступ к неоплаченному Вами товару!'); history.back(); </script>"; 

}

?>