<?php

error_reporting(-1);
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$country = $_POST['country'];
$occupation = $_POST['occupation'];
$filen = $_POST['filename'];

    $path = "uploads/"; //set your folder path
    //set the valid file extensions 
    $valid_formats = array("3g2", "3gp", "avi", "h264", "m4v", "mkv", "mov", "mp4", "mpg", "mpeg", "wmv"); //add the formats you want to upload

    $name = $_FILES['myfile']['name']; //get the name of the file
    
    $size = $_FILES['myfile']['size']; //get the size of the file

    if (strlen($name)) { //check if the file is selected or cancelled after pressing the browse button.
        list($txt, $ext) = explode(".", $name); //extract the name and extension of the file
        if (in_array($ext, $valid_formats)) { //if the file is valid go on.
            if ($size < 104857600) { // check if the file size is more than 100 mb
                $file_name = $_POST['filename']; //get the file name
                $tmp = $_FILES['myfile']['tmp_name'];
                if (move_uploaded_file($tmp, $path . $file_name.'.'.$ext)) { //check if it the file move successfully.
                    echo "File uploaded successfully!!";
                    
					// Set your email address where you want to receive emails. 
					$to = 'videos@visionquestnow.co.za';
					//$message = "$fname,$lname,$email,$country,$occupation,$filen";
					$detail = "First Name:___ " . $fname . "\r\n" . "Last Name:____ " . $lname . "\r\n" . "Email:____ " . $email . "\r\n" . "Country:______ " . $country . "\r\n" . "Occupation:________ " . $occupation . "\r\n" . "Filename:______ " . $filen . "\r\n";
					$subject = 'New Video Upload';
					$headers = "From: Video Uploads <videos@visionquestnow.co.za> \r\n";
     
					$send_email = mail($to,$subject,$detail,$headers);
	
                } else {
                    echo "failed";
                }
            } else {
                echo "File size max 100 MB";
            }
        } else {
            echo "Invalid file format..";
        }
    } else {
        echo "Please select a file..!";
    }
    exit;
}
