1 | <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/config.inc.php"); ?> |
||||
2 | <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/db_helper.php"); ?> |
||||
3 | <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/time_manip.php"); ?> |
||||
4 | <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/user_helper.php"); ?> |
||||
5 | <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/video_helper.php"); ?> |
||||
6 | <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/user_update.php"); ?> |
||||
7 | <?php $__video_h = new video_helper($__db); ?> |
||||
8 | <?php $__user_h = new user_helper($__db); ?> |
||||
9 | <?php $__user_u = new user_update($__db); ?> |
||||
10 | <?php $__db_h = new db_helper(); ?> |
||||
11 | <?php $__time_h = new time_helper(); ?> |
||||
12 | <?php |
||||
13 | $rid = ""; |
||||
14 | $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'; |
||||
15 | for ($i = 0; $i < 11; $i++) |
||||
16 | $rid .= $characters[mt_rand(0, 63)]; |
||||
17 | |||||
18 | $video_properties = (object) [ |
||||
19 | 'video_rid' => $rid, |
||||
20 | 'video_title' => $_POST['title'], |
||||
21 | 'video_description' => $_POST['description'], |
||||
22 | 'video_tags' => $_POST['tags'], |
||||
23 | 'video_category' => $_POST['category'], |
||||
24 | 'video_availability' => $_POST['privacy'], |
||||
25 | 'video_filename' => "", // we will update this later |
||||
26 | 'video_thumbnail' => "", |
||||
27 | 'video_xml' => "", |
||||
28 | 'video_duration' => 0, |
||||
29 | 'video_author' => $_SESSION['siteusername'] |
||||
30 | ]; |
||||
31 | |||||
32 | $video_validation = (object) [ |
||||
33 | 'upload_ok' => true, |
||||
34 | 'upload_error' => "", |
||||
35 | 'moved_files' => true, |
||||
36 | 'video_file_type' => "." . strtolower(pathinfo($_FILES["video_file"]["name"], PATHINFO_EXTENSION)), |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
37 | 'target_upload_name' => md5_file($_FILES["video_file"]["tmp_name"]) . ".mp4", |
||||
38 | ]; |
||||
39 | |||||
40 | // $_FILES['video_file']['tmp_name'] = substr_replace($_FILES['video_file']['tmp_name'], '/', 8, 0); |
||||
41 | /* -- /tmp/phpfAN4Xu -- Why in the fuck does this happen? I love PHP */ |
||||
42 | |||||
43 | if($__user_h->if_upload_cooldown($_SESSION['siteusername'])) { |
||||
44 | $video_validation->upload_error = "Under an upload cooldown"; |
||||
45 | $video_validation->upload_ok = 0; |
||||
46 | } |
||||
47 | |||||
48 | if(move_uploaded_file( |
||||
49 | $_FILES['video_file']['tmp_name'], |
||||
50 | "../dynamic/temp/" . $video_properties->video_rid . $video_validation->video_file_type |
||||
51 | )) { |
||||
52 | $video_properties->video_filename = "../dynamic/temp/" . $video_properties->video_rid . $video_validation->video_file_type; |
||||
53 | } else { |
||||
54 | $video_validation->upload_error = "Failed to move temp file to dynamic folder. Pottential IO/permission problem." . $_FILES['video_file']['error']; |
||||
55 | $video_validation->upload_ok = 0; |
||||
56 | } |
||||
57 | |||||
58 | if( $video_validation->video_file_type == ".png" || |
||||
59 | $video_validation->video_file_type == ".jpg" || |
||||
60 | $video_validation->video_file_type == ".jpeg" || |
||||
61 | $video_validation->video_file_type == ".gif" |
||||
62 | ) { |
||||
63 | $video_validation->upload_error = "You cannot upload an image as a video." . $_FILES['video_file']['error']; |
||||
64 | $video_validation->upload_ok = 0; |
||||
65 | } |
||||
66 | |||||
67 | |||||
68 | /* |
||||
69 | I'm going to hopefully guess that |
||||
70 | user input is fine because I moved |
||||
71 | the temp video name to a randomly |
||||
72 | generated video ID..... |
||||
73 | */ |
||||
74 | |||||
75 | if ($video_validation->upload_ok == true) { |
||||
76 | |||||
77 | /* Get the video duration. */ |
||||
78 | $video_properties->video_duration = shell_exec(' |
||||
79 | ' . $__server->ffprobe_binary . ' -i "' . $video_properties->video_filename . '" -show_entries format=duration -v quiet -of csv="p=0" 2>&1 |
||||
80 | '); |
||||
81 | |||||
82 | $video_properties->video_duration = round($video_properties->video_duration); |
||||
0 ignored issues
–
show
$video_properties->video_duration of type null|string is incompatible with the type double|integer expected by parameter $num of round() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
83 | |||||
84 | /* Process the video... */ |
||||
85 | $video_validation->video_processing_logs = shell_exec(' |
||||
86 | ' . $__server->ffmpeg_binary . ' -hide_banner -loglevel error -i "' . $video_properties->video_filename . '" -vcodec h264 -acodec aac -pix_fmt yuv420p -threads 2 -preset medium -vf "scale=-1:480,pad=ceil(iw/2)*2:ceil(ih/2)*2" -b:v 1500k "../dynamic/videos/' . $video_properties->video_rid . '.mp4" 2>&1 |
||||
87 | '); |
||||
88 | |||||
89 | |||||
90 | /* Process the thumbnail... */ |
||||
91 | $video_properties->video_thumbnail = shell_exec(' |
||||
92 | ' . $__server->ffmpeg_binary . ' -hide_banner -loglevel error -i "../dynamic/videos/' . $video_properties->video_rid . '.mp4" -vf "select=eq(n\\,34),scale=-1:360" -vframes 1 "../dynamic/thumbs/' . $video_properties->video_rid . '.png" 2>&1 |
||||
93 | '); |
||||
94 | |||||
95 | /* For some reason, I have to do this manually for only the thumbnail */ |
||||
96 | |||||
97 | /* TODO: fetch 3 pngs' from video stream and somehow get them to the |
||||
98 | ploader and let the user select which auto-gen thumbnail is best */ |
||||
99 | $video_properties->video_thumbnail = $video_properties->video_rid . '.png'; |
||||
100 | $video_properties->video_filename = $video_properties->video_rid . '.mp4'; |
||||
101 | |||||
102 | $stmt = $__db->prepare("INSERT INTO videos |
||||
103 | (title, author, filename, thumbnail, description, tags, rid, duration, xml, category) |
||||
104 | VALUES |
||||
105 | (:title, :author, :filename, :thumbnail, :description, :tags, :rid, :duration, :xml, :category)"); |
||||
106 | $stmt->bindParam(":title", $video_properties->video_title); |
||||
107 | $stmt->bindParam(":author", $video_properties->video_author); |
||||
108 | $stmt->bindParam(":filename", $video_properties->video_filename); |
||||
109 | $stmt->bindParam(":thumbnail", $video_properties->video_thumbnail); |
||||
110 | $stmt->bindParam(":description", $video_properties->video_description); |
||||
111 | $stmt->bindParam(":tags", $video_properties->video_tags); |
||||
112 | $stmt->bindParam(":rid", $video_properties->video_rid); |
||||
113 | $stmt->bindParam(":duration", $video_properties->video_duration); |
||||
114 | $stmt->bindParam(":xml", $video_properties->video_xml); |
||||
115 | $stmt->bindParam(":category", $video_properties->video_category); |
||||
116 | $stmt->execute(); |
||||
117 | |||||
118 | $__user_u->update_cooldown_time($_SESSION['siteusername'], "upload_cooldown"); |
||||
119 | echo($video_properties->video_rid); |
||||
120 | } else { |
||||
121 | die($video_validation->upload_error); |
||||
122 | } |
||||
123 | ?> |
||||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |