-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_uploader.php
93 lines (59 loc) · 1.95 KB
/
video_uploader.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require 'init.php';
session_regenerate_id(true);
$function_out = strcmp($_SESSION['usertype'], '1');
if(!isset($_SESSION['id']))
{
header('location: login.php');
exit;
}
else
{
if($function_out == 0)
{
header("location: home.php");
}
}
include('config.php');
if(isset($_POST['posting']))
{
$filename = $_FILES["file"]["name"];
$tempname = $_FILES["file"]["tmp_name"];
$filename_thumb = $_FILES["thumbnail"]["name"];
$thumb_temp_name = $_FILES["thumbnail"]["tmp_name"];
$file_type = pathinfo($filename_thumb, PATHINFO_EXTENSION);
$file_extansion = pathinfo($filename, PATHINFO_EXTENSION);
$random_number = rand(0, 10000000);
$file_rename = 'Vid_'.date('Ymd').$random_number;
$file_complete = $file_rename.'.'.$file_extansion;
$thumbnail_name = 'Thumb_'.date('Ymd').$random_number;
$thumbnail_name_complete = $thumbnail_name.'.'.$file_type;
$folder = "./assets/videos/" . $file_complete;
$second_file = "./assets/videos/" . $thumbnail_name_complete;
$ID = $_SESSION['id'];
$caption = $_POST['caption'];
$hashtags= $_POST['hash-tags'];
$likes = 0;
$date = date("Y-m-d");
$sql_query = "INSERT INTO videos (User_ID, Likes, Video_Path, Caption, HashTags, Date_Upload, Thumbnail_Path)VALUES($ID, $likes, '$file_complete','$caption', '$hashtags', '$date', '$thumbnail_name_complete')";
echo $sql_query;
$stmt = $conn->prepare($sql_query);
if($stmt->execute())
{
move_uploaded_file($tempname, $folder);
move_uploaded_file($thumb_temp_name, $second_file);
header("location: video_upload.php?success_message=Post Successfully updated");
exit;
}
else
{
header("location: video_upload.php?error_message=Error Occurred, try again - ERROR #008");
exit;
}
}
else
{
header("location: video_upload.php?error_message=Error Occurred, try again2 - ERROR #009");
exit;
}
?>