-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorruptionup.php
76 lines (73 loc) · 2.7 KB
/
corruptionup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
include("includes/header.php");
?>
<link rel="stylesheet" href="./css/corruption_upload.css" />
<?php
include("includes/nav.php");
include("includes/db.php");
if(!isset($_SESSION["username"])){
header("Location: login.php?location=".urlencode($_SERVER['REQUEST_URI']));
}
if(isset($_POST["submit"])){
$filepath = $_FILES['videofile']['tmp_name'];
$fileSize = filesize($filepath);
$fileinfo = finfo_open(FILEINFO_MIME_TYPE);
$filetype = finfo_file($fileinfo, $filepath);
$allowedTypes = [ 'video/mp4' => 'mp4',
'video/webm' => 'webm'
];
if ($fileSize === 0) {
die("The file is empty.");
}
if(!in_array($filetype, array_keys($allowedTypes))) {
die("File not allowed. Only .mp4 and .webm are supported");
}
$filename = md5(date("h:i:sa"));
$extension = $allowedTypes[$filetype];
$targetDirectory = __DIR__ . "/uploads";
$newFilepath = $targetDirectory . "/" . $filename . "." . $extension;
if (!copy($filepath, $newFilepath )) { die("Can't move file.");
}
unlink($filepath);
echo "Submitted Successfully";
//db entries
$vidurl = $filename.".".$extension;
$description = $_POST["description"];
$sqlquery = "INSERT into corruption values(NULL,'$vidurl','$description',current_timestamp())";
mysqli_query($conn,$sqlquery);
header("Location: corruption.php");
}
?>
<div class="upload-container">
<h1>Video Upload</h1>
<form method="post" enctype="multipart/form-data" id="upload-form" action="corruptionup.php">
<div class="form-group">
<label for="videofile" class="vdo"><h2 class="vdo">Select Video</h2></label>
<input type="file" id="videofile" name="videofile" accept="video/*" required>
</div>
<div class="form-group">
<label for="description"><h3>Description</h3></label>
<textarea id="description" name="description" cols="65" rows="10" placeholder="write about video"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit">Upload</button>
</div>
</form>
</div>
<?php include("includes/footer.php"); ?>
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form method="post" action="corruptionup.php" enctype="multipart/form-data">
<input type="text" name="description" placeholder="Description" ><br>
<input type="file" name="videofile"><br>
<input type="submit" name="submit"><br>
</form>
</body>
</html>-->