
<head>
<style>
.button {
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  padding: 6px 22px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button {
  background-color: white; 
  color: black; 
  border: 2px solid #4CAF50;
  border-radius: 12px;
}

.button:hover {
  background-color: #4CAF50;
  color: white;
}

</style>
</head>


<?php
  

$host = "localhost"; /* Host name */
$user = "root"; /* User */
$password = ""; /* Password */
$dbname = "quizapp"; /* Database name */

$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
  die("Connection failed: " . mysqli_connect_error());
}
      ?>  


      <?php                    
                         
if(isset($_POST['but_upload'])){
   $maxsize = 5242880; // 5MB
   if(isset($_FILES['file']['name']) && $_FILES['file']['name'] != ''){
       $name = $_FILES['file']['name'];
       $target_dir = "../images/questions/";
       $target_file = $target_dir . $_FILES["file"]["name"];
         $subject=$obj->sanitize($conn,$_POST['subject']);
                            $topic=$obj->sanitize($conn,$_POST['topic']);
                             $content=$obj->sanitize($conn,$_POST['content']);

       // Select file type
       $extension = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

       // Valid file extensions
       $extensions_arr = array("mp4","avi","3gp","mov","mpeg","jpg","png");

       // Check extension
       if( in_array($extension,$extensions_arr) ){
 
          // Check file size
          if(($_FILES['file']['size'] >= $maxsize) || ($_FILES["file"]["size"] == 0)) {
             $_SESSION['message'] = "File too large. File must be less than 5MB.";
          }else{
             // Upload
             if(move_uploaded_file($_FILES['file']['tmp_name'],$target_file)){
               // Insert record
               $query = "INSERT INTO videos(name,location,subject,topic,content) VALUES('".$name."','".$target_file."','".$subject."','".$topic."','".$content."')";

               mysqli_query($con,$query);
               $_SESSION['message'] = "Upload successfully.";
             }
          }

       }else{
          $_SESSION['message'] = "Invalid file extension.";
       }
   }else{
       $_SESSION['message'] = "Please select a file.";
   }

   exit;
} 
?>
<!doctype html> 
<html> 
  
  <body>

    <!-- Upload response -->
    <?php 
    if(isset($_SESSION['message'])){
       echo $_SESSION['message'];
       unset($_SESSION['message']);
    }
    ?>
    <script type="text/javascript">
    function preview() {
    frame.src=URL.createObjectURL(event.target.files[0]);
}</script>
     <div class="container">
    <div class="title">Registration</div>
    <div class="content">
                    <a href="<?php echo SITEURL; ?>admin/index.php?page=students"><img src="../box/assets/img/unnamed.png" alt="" class="header__img"></a>

    <form method="post" action="" enctype='multipart/form-data'class="forms">
       <div class="user-details"><img id="frame" src="" width="600px" height="600px"/>
                            <div class="input-box">
                        <span class="details">Subject</span> 
                        <input type="text" name="subject" placeholder="subject" required="true" /> </div>
                        
                        <div class="user-details">
                            <div class="input-box">
                        <span class="details">Topic</span>
                        <input type="text" name="topic" placeholder="topic" required="true" />
</div>
<div class="user-details">
                            <div class="input-box">
                        <span class="details">Content</span>
                        <input type="text" name="content" placeholder="content" required="true" />
</div>


      <input type='file' name='file' class="button"onchange="preview()" />
      <input type='submit' value='Upload' name='but_upload'class="button"/>
      
    </form>
</div>
  </div>
  </div>
  </body>
</html>