<?php
session_start();

include ("var.php");

include("stop.php");
?>
<?php
include ("config.php");

if(isset($_SESSION['nume'])) {
      	$usernames = ''.$_SESSION['nume'].'';
$stare = "Upload File";
if(!$act){mysql_query("UPDATE utilizatori SET stare='$stare' WHERE nume='$usernames'");}
}


include ("upload.html");

echo "<table width='950' cellspacing='0' cellpadding='0' align='center'>";

include ("right.html");
?>
<td width='760' valign='top' class='continut'>
<table cellspacing='0' cellpadding='10'  width='100%'>
<tr>
<td>
<?php
session_start();
include("stop.php");
?>

<link rel='stylesheet' href='stil.css' type='text/css' />
<script>
 var upload_status = 0;
 function goUpload() {
 upload_status = 1;
 }
 function askExit() {
 alert('No exit!');
 return false;
 }
 function SelectItem(index)
 {
 document.uploadform.category.selectedIndex = index
 }
 function switchCategory(value) {
 var audio = 'mp3 wav wma mid midi amr mmf';
 var video = 'asf avi mpg mpeg wmv flv';
 var movie = 'mp4 3gp'
 var symbian = 'sis sisx';
 var wm = 'cab';
 var images = 'jpg gif bmp jpeg png';
 //var images1 = 'jpg';
 var programe = 'exe msi';
 var gadget = 'gadget';
 var s40 = 'nth';
 var se = 'thm';
 var java = 'jar jad';
 var torrent = 'torrent';
 var ipa = 'ipa';
 var apk = 'apk';
 var ext = value.lastIndexOf(".");
 ext =   value.substr(ext+1);
 ext = ext.toLowerCase();
 
 
   if (value.indexOf("'") != -1) alert('Apostroph in filename is not accepted!');
   if (audio.indexOf(ext) != -1) SelectItem(2);
   else if (video.indexOf(ext) != -1) SelectItem(15);
   else if (movie.indexOf(ext) != -1) SelectItem(36);
   else if (symbian.indexOf(ext) != -1) SelectItem(10);
   else if (wm.indexOf(ext) != -1) SelectItem(17);
   else if (images.indexOf(ext) != -1) SelectItem(7);
   else if (programe.indexOf(ext) != -1) SelectItem(16);
   else if (gadget.indexOf(ext) != -1) SelectItem(17);
   else if (s40.indexOf(ext) != -1) SelectItem(20);
   else if (se.indexOf(ext) != -1) SelectItem(19);
   else if (java.indexOf(ext) != -1) SelectItem(10);
   else if (torrent.indexOf(ext) != -1) SelectItem(17);
   //else if (images1.indexOf(ext) != -1) SelectItem(21);
   else if (ipa.indexOf(ext) != -1) SelectItem(28);
   else if (apk.indexOf(ext) != -1) SelectItem(1);
   else alert('Va rugam selectati o categorie.');
   //document.getElementById('catnote').innerHTML = alert('Va rugam selectati o categorie.</b>');

   
 }
 </script>

<? $cookie_name = 'extremshare';
setcookie ($cookie_name, 1, time()+1150, '/ ', '', 0);
?>
<!-- CONTINUTUL !!!! -->
<?
echo "<div class='hl'>Upload</div><center>";
echo "</center>";

include("config.php");

$time = date("d.m.Y, H:i:s");
$Browser =  $_SERVER[HTTP_USER_AGENT];
$Browser = htmlspecialchars($Browser, ENT_QUOTES);
$ip=$_SERVER[REMOTE_ADDR];
$desc=trim($_POST['desc']);
$username=trim($_POST['username']);
$category = $_POST['category'];
$desc = htmlspecialchars($desc, ENT_QUOTES);


if(!$desc) $desc="none";
if(!$username) $user="Guest";
$no="no";
echo "<div class='txt'> <div class='Emessage'><b>Alert: </b>Please do not upload files that contain links that will be deleted!</div></br>
";

if($_GET[page] !=="add"){
echo "<form method='post' enctype='multipart/form-data' name='uploadform' action='upload.php?page=add'>";

echo "<input type='file' name='filetoupload' onchange='switchCategory(this.value)'><br>";

echo "<b>Category</b> <select name='category'>";
$sql = mysql_query("SELECT * FROM categorii ORDER BY name");
while($row = mysql_fetch_array($sql)){    
echo "<option value='$row[id]'>$row[name]</option>";}
echo "</select>
<br/>
</div>";

echo "<input type=\"Submit\" name=\"uploadform\" value=\"Upload File\">";
echo "(max. <b>50</b> MB)</div>";
echo "<div class=\"hl\">Optional</div>";


if(isset($_SESSION['nume'])) {
      	$usersa = ''.$_SESSION['nume'].'';
echo "<div class=\"txt\">";
echo "<br/><input type=\"hidden\" name=\"username\" value=\"$usersa\"/>";
}else{
	echo "<div class=\"txt\"><b>User:</b>";
echo "<br/><input type=\"text\" name=\"username\" size=\"30\" /><br/>";
}
echo "<br/><input type=\"hidden\" name=\"pass\" value=\"octavian\"/>";
echo "<div class=\"txt\"><b>Description:</b>";
echo "<br/><textarea name=\"desc\" rows=\"4\" cols=\"40\"></textarea><br/>";

echo "<small>Notice: once you submit the file, it will be available to public.</small>";
echo "<br/><b>Please wait while the file is uploaded, it may take several minutes depending by the size of the file and by your internet bandwidth.</b>";
echo "</div>";
echo "</form>";

}



if ($_REQUEST[file1]) {
$file1 = $_REQUEST[file1];
$file1 = explode("=", $file1);
$file_content = $file1[1];
$filename = str_replace("file", "", $file1[0]);

$size = strlen($file_content);


}
else {

$filename = $_FILES['filetoupload']['name'];
$size = $_FILES['filetoupload']['size'];
}
$ext = strrchr($filename,'.');
$truext=str_replace(".","",$ext);
$truext=strtolower($truext);
$ext=strtolower($ext);
$upload_dir=htmlspecialchars("uploads/$truext/");

$filename=str_replace(" ","_",$filename);
$filename=str_replace("`","_",$filename);
$filename=str_replace("]","_",$filename);
$filename=str_replace("[","_",$filename);
$filename=str_replace(".php.",".",$filename);
$filename=str_replace("~","_",$filename);
$filename=str_replace("@","_",$filename);
$filename=str_replace("#","_",$filename);
$filename=str_replace("%","_",$filename);
$filename=str_replace("^","_",$filename);
$filename=str_replace("www.","_",$filename);
$filename=str_replace(".net","_",$filename);
$filename=str_replace(".ro","_",$filename);
$filename=str_replace(".com","_",$filename);
$filename=str_replace(".info","_",$filename);
$filename=str_replace(".biz","_",$filename);
$filename=str_replace(".org","_",$filename);
$filename=str_replace("http://","_",$filename);
$filename=str_replace(".hi2","_",$filename);
$filename=str_replace("wWw.","_",$filename);
$filename=str_replace("WwW.","_",$filename);
$filename=str_replace("WWW.","_",$filename);
$filename=str_replace(".Net","_",$filename);
$filename=str_replace(".Ro","_",$filename);
$filename=str_replace(".Com","_",$filename);
$filename=str_replace(".Info","_",$filename);
$filename=str_replace(".Biz","_",$filename);
$filename=str_replace(".Org","_",$filename);
$filename=str_replace("http://","_",$filename);
$filename=str_replace(".Hi2","_",$filename);
$filename=str_replace("*","_",$filename);
$filename=str_replace("|","_",$filename);
$filename=str_replace("$","_",$filename);
$filename=str_replace("&lt;","_",$filename);
$filename=str_replace("<","_",$filename);
$filename=str_replace(">","_",$filename);
$filename=str_replace("&gt;","_",$filename);
$filename=str_replace("\"","_",$filename);
$filename=str_replace("'","_",$filename);

if($_GET['page']=="add"){

if (!$filename)
{
echo "<b>Please select a file for upload.</b><br />";
die();
}
$pass = $_POST["pass"];
if (!$pass)
{
echo "<b>Please upload file from website.</b><br />";
die();
}

if ($act)
{
include("stop.php");
}

if (($extlimit == "yes") && (in_array($ext,$limitedext)))
{
echo("Extension <b>$ext</b> was disabled due security reasons.The file was NOT uploaded!<br />");
echo "<br />";
die();
}


if(strlen($filename)>$lungime_nume)
{
echo "<b><font color=\"red\">Your file name has a name too long.Please rename it!</font></b><br />";
die();
}



if ($size > $size_bytes)
{
echo "<b><font color=\"red\">Your file size is too big.Maximum allowed is $mb MB.</font></b><br />";
die();
}

if (file_exists("$upload_dir/$filename"))
{
echo("<b><font color=\"red\">File already exist.Please rename your file!</font></b><br />");
die();
}

if ($file1) {
if(!is_dir($upload_dir)){mkdir($upload_dir); chmod($upload_dir,0777); copy("htaccess.txt","$upload_dir.htaccess");}

$fp = fopen($upload_dir.$filename, "w") or die("File cannot be saved due server permissions");

fwrite($fp, base64_decode($file_content));
if (fclose($fp)) $Uploaded = TRUE;


}
else {
if(!is_dir($upload_dir)){mkdir($upload_dir); chmod($upload_dir,0777); copy("htaccess.txt","$upload_dir.htaccess");}
move_uploaded_file($_FILES['filetoupload']['tmp_name'], $upload_dir.$filename) or die("Cannot move uploaded file");
$Uploaded = TRUE;
}

if ($Uploaded)
{
mysql_query("INSERT INTO fisiere (banned,file,user,browse,ip,ftype,uploaded,description,size,categorie,time) VALUES ('$no','$filename','$username','$Browser','$ip','$truext','$time','$desc','$size','$category' , '".time()."')");
$sql = mysql_query("SELECT * FROM fisiere WHERE file = '$filename' ");


$idir = "uploads/$truext/";   // Path To Images Directory
$tdir = "thumb/";   // Path To Thumbnails Directory
$twidth = "100";   // Maximum Width For Thumbnail Images
$theight = "100";   // Maximum Height For Thumbnail Images
 
if(in_array($truext,array("gif","jpg","jpeg","png"))){ 
    
  $urls = $filename;   // Set $url To Equal The Filename For Later Use]
  
 if(in_array($truext,array("jpeg"))){
    $simg = imagecreatefromjpeg("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
if(in_array($truext,array("jpg"))){
    $simg = imagecreatefromjpeg("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
 if(in_array($truext,array("gif"))){
    $simg = imagecreatefromgif("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
if(in_array($truext,array("png"))){
    $simg = imagecreatefrompng("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
      $currwidth = imagesx($simg);   // Current Image Width
      $currheight = imagesy($simg);   // Current Image Height
      if ($currheight > $currwidth) {   // If Height Is Greater Than Width
         $zoom = $twidth / $currheight;   // Length Ratio For Width
         $newheight = $theight;   // Height Is Equal To Max Height
         $newwidth = $currwidth * $zoom;   // Creates The New Width
      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
        $zoom = $twidth / $currwidth;   // Length Ratio For Height
        $newwidth = $twidth;   // Width Is Equal To Max Width
        $newheight = $currheight * $zoom;   // Creates The New Height
      }
      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
      $palsize = ImageColorsTotal($simg);
      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
      }
      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
      imagejpeg($dimg, "$tdir" . $urls);   // Saving The Image
      imagedestroy($simg);   // Destroying The Temporary Image
      imagedestroy($dimg);   // Destroying The Other Temporary Image
      print 'Image thumbnail created successfully.</br>';   // Resize successful
  }



$top="SELECT * from utilizatori where nume='$username'"; 
$top2=mysql_query($top);
while($top3=mysql_fetch_array($top2))
{
$setup = $top3["fisiere"]; 
$cpts = $top3["ptup"];
} 
$setup = $setup+1; 
$topup="UPDATE utilizatori SET fisiere='$setup' WHERE nume='$username'";
  
  mysql_query($topup); 
while($row = mysql_fetch_array($sql)){
$id = $row['id'];}

$pts = $cpts+5;

$ptup="UPDATE utilizatori SET ptup='$pts' WHERE nume='$username'";

mysql_query($ptup); 

echo ("<b><font color=\"red\">Your file was uploaded </font><a href=\"file.php?id=$id\">here</a></b><br />
<div class='hl'>Share link</div>
  <div class='txt'>
<u>Copy and paste the following code:</u><br />
<u><a href=\"file.php?id=$id\">".$url."/file.php?id=".$id."</a></u></br>
<textarea name='link' rows='5' cols='40' onclick='javascript:this.select()'>".$url."/file.php?id=".$id."</textarea><br /></div></div>");

echo "</form>
</center>";
echo "</td></tr></table>
</tr>

<tr>
<td width='180'>&nbsp;
</td>";
die();
}
else
{


echo "<b><font color=\"red\">Unexpected error.Please try again.</font></b><br />";
echo "<br />";
die();
}

}
?>

<div class='hl'>Rules &amp; Terms</div>
<div class='txt'>
- <font color='red'>Please don't use ' (apostroph) in the filename</font><br/>
- You are not allowed to upload imoral material <br/>
- You are not allowed to share infected applications with virus, trojans, backdoors, etc<br/>
- You are soley responsible for the content you are uploading on this site
<br/><br/>
<b>If you don't respect the rules your account shall be
<font color='red'>banned permanently</font>
and/or all uploaded files  deleted.</b>
<br/><br/><a href='rules.php'>Please take a look on the complete rules section.</a>
   </div>

</form>
</center></td></tr></table>
</tr><tr>
<td width='180'>
</td>
<?php
include ("flooter.html");
?>