<?php

	include('connect.php');	
	
	$filedesc= $_POST['desc'];
	$fname= $_POST['fname'];
	
	///////////////////////////////////////
	$queryyp = "SELECT * FROM class2 where college_roll='$fname'";
	$numresultsyp=mysql_query($queryyp);
	$resultyp= mysql_query($queryyp) or die("Couldn't execute query");
	$a_rowwp = mysql_fetch_array( $resultyp );
	$crollp=$a_rowwp['college_roll'];
	////////////////////////////////////
	
	
	if($crollp==""){
	
	?>
    <h1>Student Roll Number not Found............</h1>
    <a href="index.php">Go to Main Page</a>
    <?php }else{
	
   define ("FILEREPOSITORY","uploads/");

   if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])) {

      if ($_FILES['uploaded_file']['type'] != "application/pdf") {
         echo "<h2> must be uploaded in PDF format.</h2>";
      } else {
         $rd2 = mt_rand(1000,9999);
		 
         $result = move_uploaded_file($_FILES['uploaded_file']['tmp_name'], FILEREPOSITORY."/".$rd2."$fname.pdf");
         if ($result == 1) {echo "<p>File successfully uploaded.</p>";
		 $nupload=$rd2."$fname.pdf";
		 $upd_qryb="INSERT INTO up_files (fdesc,floc,fdatein,fname) VALUES ('$filedesc','$nupload',NOW(),'$fname')";
				mysql_query($upd_qryb); 
				?><script type="text/javascript">
   	// Javascript URL redirection
    window.location.replace("index.php?fname=<?php echo $fname; ?>");
</script>
                <?php
		 }else{echo "<p>There was a problem uploading the file.1</p>";}
      } #endIF
   } #endIF
  
   
		
		
		}
      	
	
?>


