-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
110 lines (91 loc) · 3.46 KB
/
functions.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
// functions.php
function cleanURL($url) {
$cleanedURL = str_replace("\\", "/", $url);
$cleanedURL = preg_replace("#(https://+)/#i", "https://", $cleanedURL);
return $cleanedURL;
}
function handleAPIRequest() {
$response = [];
if (isset($_GET['url']) && !empty($_GET['url'])) {
$externalFileUrl = cleanURL($_GET['url']);
$fileInfo = pathinfo($externalFileUrl);
$fileName = $fileInfo['filename'];
$fileExtension = $fileInfo['extension'];
$fileContent = file_get_contents($externalFileUrl);
if ($fileContent !== false) {
$fileSizeBytes = strlen($fileContent);
$fileSizeMB = number_format($fileSizeBytes / 1048576, 2);
$localFilePath = "file/" . $fileName . "." . $fileExtension;
file_put_contents($localFilePath, $fileContent);
$localFileUrl = "https://" . $_SERVER['HTTP_HOST'] . "/" . $localFilePath;
$data = [
"file name" => $fileName,
"file size" => $fileSizeMB . " MB",
"mime" => mime_content_type($localFilePath),
"path" => $localFilePath,
"ext" => $fileExtension,
"fileurl" => $localFileUrl,
];
$response = [
"author" => "Miftah GanzZ",
"status" => "success",
"code" => 200,
"data" => $data,
];
} else {
$response = [
"author" => "Miftah GanzZ",
"status" => "error",
"code" => 400,
"message" => "Failed to download the file from the provided URL.",
];
http_response_code(400);
}
} else {
$response = [
"author" => "Miftah GanzZ",
"status" => "error",
"code" => 400,
"message" => "Parameter 'url' must be provided and not empty.",
];
http_response_code(400);
}
header("Content-Type: application/json");
$jsonResponse = json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo $jsonResponse;
exit;
}
if (isset($_GET['url'])) {
handleAPIRequest();
}
function translate($text, $language) {
$translations = [
'en' => [
'image_uploader' => 'Image Uploader',
'choose_image' => 'Choose an image:',
'upload' => 'Upload',
'select_image' => 'Please select an image to upload.',
'uploading' => 'Uploading...',
'image_uploaded_successfully' => 'Image Uploaded Successfully!',
'image_upload_error' => 'Failed to upload the image or unsupported image type.',
'copy_url' => 'Copy URL',
'url_copied' => 'URL Copied!',
'select_language' => 'Select Language:',
],
'id' => [
'image_uploader' => 'Pengunggah Gambar',
'choose_image' => 'Pilih gambar:',
'upload' => 'Unggah',
'select_image' => 'Silakan pilih gambar yang akan diunggah.',
'uploading' => 'Mengunggah...',
'image_uploaded_successfully' => 'Gambar Diunggah dengan Sukses!',
'image_upload_error' => 'Gagal mengunggah gambar atau jenis gambar tidak didukung.',
'copy_url' => 'Salin URL',
'url_copied' => 'URL Disalin!',
'select_language' => 'Pilih Bahasa:',
],
];
return $translations[$language][$text] ?? $text;
}
?>