-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
119 lines (107 loc) · 4.28 KB
/
Copy pathfunctions.php
File metadata and controls
119 lines (107 loc) · 4.28 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
include "config.php";
function generateRandomString($length = 5) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function rand_color()
{
return "#" . str_pad(dechex(mt_rand(0, 0xffffff)), 6, "0", STR_PAD_LEFT);
}
function remove_exif($in, $out)
{
$buffer_len = 4096;
$fd_in = fopen($in, 'rb');
$fd_out = fopen($out, 'wb');
while ($buffer = fread($fd_in, $buffer_len)) {
// \xFF\xE1\xHH\xLLExif\x00\x00 - Exif
// \xFF\xE1\xHH\xLLhttp:// - XMP
// \xFF\xE2\xHH\xLLICC_PROFILE - ICC
// \xFF\xED\xHH\xLLPhotoshop - PH
while (
preg_match(
'/\xFF[\xE1\xE2\xED\xEE](.)(.)(exif|photoshop|http:|icc_profile|adobe)/si',
$buffer,
$match,
PREG_OFFSET_CAPTURE
)
) {
$len = ord($match[1][0]) * 256 + ord($match[2][0]);
fwrite($fd_out, substr($buffer, 0, $match[0][1]));
$filepos = $match[0][1] + 2 + $len - strlen($buffer);
fseek($fd_in, $filepos, SEEK_CUR);
$buffer = fread($fd_in, $buffer_len);
}
fwrite($fd_out, $buffer, strlen($buffer));
}
fclose($fd_out);
fclose($fd_in);
}
function GeneratePage($length, $file)
{
include 'config.php';
$generatedSymbols = generateRandomString();
$tmpName = $file['sharex']['tmp_name'];
$fileSize = $file['sharex']['size'] >> 10;
$originalName = $file['sharex']['name'];
date_default_timezone_set('Europe/Vienna');
$uploadTime = date('l\, F jS\, Y, H:i');
$encEmojis = urlencode($generatedSymbols);
$target_file = $_FILES['sharex']['name'];
$color = rand_color();
$directoryPath = "media/{$generatedSymbols}";
mkdir($directoryPath, 0777, true);
chmod($directoryPath, 0777);
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
$originalFileType = $fileType;
// Select the appropriate template file based on the file type
if ($fileType == 'mp4' || $fileType == 'webm' || $fileType == 'ogg') {
$templateFile = 'templates/template_video.html';
} elseif (
$fileType == 'mov' ||
$fileType == 'wmv' ||
$fileType == 'avi' ||
$fileType == 'avchd' ||
$fileType == 'mkv'
) {
$templateFile = 'templates/template_video_others.html';
$fileType = 'mp4'; // Set the file type to mp4 as html does not support playback of e.g. mov video format. $originalFileType still contains the original file type e.g. for download.
} elseif (
$fileType == 'jpeg' ||
$fileType == 'png' ||
$fileType == 'gif' ||
$fileType == 'tiff' ||
$fileType == 'jpg' ||
$fileType == 'jfif'
) {
$templateFile = 'templates/template_image.html';
}
// Read the template file
$template = file_get_contents($templateFile);
// Replace the placeholders with dynamic values
$template = str_replace('%color%', $color, $template);
$template = str_replace('%originalName%', $originalName, $template);
$template = str_replace('%fileSize%', $fileSize, $template);
$template = str_replace('%fileType%', $fileType, $template);
$template = str_replace('%uploadTime%', $uploadTime, $template);
$template = str_replace('%imgurl%', "{$directoryPath}/image.{$fileType}", $template);
$template = str_replace('%originalType%', $originalFileType, $template);
$template = str_replace('%generatedSymbols%', $generatedSymbols, $template);
$template = str_replace('%author%', $author, $template);
$template = str_replace('%mediafolder%', $mediafolder, $template);
$template = str_replace('%sitename%', $sitename, $template);
$target_file = $_FILES['sharex']['name'];
$tmpName = $file['sharex']['tmp_name'];
if (move_uploaded_file($tmpName, "{$directoryPath}/old.{$fileType}")) {
remove_exif("{$directoryPath}/old.{$fileType}", "{$directoryPath}/image.{$fileType}");
unlink("{$directoryPath}/old.{$fileType}");
file_put_contents("{$directoryPath}/index.html", $template);
chmod($directoryPath, 0755);
return $generatedSymbols;
}
}