g6.1
This commit is contained in:
1 parent
28490ce8b3
commit
f5704e87df
2 files changed
+12
-53
No files matched your search
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
function isFileExtImage(string $fileExt) :bool {
|
||||
switch ($fileExt) {
|
||||
case 'png':
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'ico':
|
||||
case 'gif':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function res_mixed(bool $success, mixed $data = null, string $except = null) :object {
|
||||
return $success ? res_ok($data): res_err($data ?? $except);
|
||||
}
|
||||
function res_ok(mixed $data = null) :object {
|
||||
return (object) [
|
||||
"type" => "success",
|
||||
"data" => $data
|
||||
];
|
||||
}
|
||||
function res_err(string|null $message = null) :object {
|
||||
return (object) [
|
||||
"type" => "error",
|
||||
"message" => $message
|
||||
];
|
||||
}
|
||||
+12
-23
@@ -1,13 +1,8 @@
|
||||
<?php
|
||||
|
||||
require_once 'features.php';
|
||||
|
||||
///A collection of given paths
|
||||
class TurtlePathInfo {
|
||||
public string $content;
|
||||
}
|
||||
|
||||
///Parse url and execute it
|
||||
class TurtleURLObject {
|
||||
public static function create_from_server(bool $lowerCase = true, bool $alternativeURL = true) :TurtleURLObject {
|
||||
$urlParts = explode('?', trim($_SERVER['REQUEST_URI'], '/'));
|
||||
@@ -37,9 +32,6 @@ class TurtleURLObject {
|
||||
$bodyContent = file_get_contents("php://input");
|
||||
return $bodyContent;
|
||||
}
|
||||
public function get_body_json() :mixed {
|
||||
return json_decode($this->get_body_text());
|
||||
}
|
||||
|
||||
public function get_html_file(string $file_path): string {
|
||||
if (!file_exists($file_path)) {
|
||||
@@ -48,7 +40,6 @@ class TurtleURLObject {
|
||||
return file_get_contents($file_path);
|
||||
}
|
||||
}
|
||||
|
||||
public function send_text(string $text) :void {
|
||||
header('Content-Type: text/plain');
|
||||
echo $text;
|
||||
@@ -95,20 +86,6 @@ class TurtleURLObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function send_download_file(string $path) :bool {
|
||||
if (!file_exists($path)) return false;
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'.basename($path).'"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($path));
|
||||
|
||||
readfile($path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function is_image_request() :bool {
|
||||
foreach ($this->method_type as $type) {
|
||||
if (!str_starts_with($type, "image/")) return false;
|
||||
@@ -165,3 +142,15 @@ function _parseUrlMark($urlParts) :object {
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
function isFileExtImage(string $fileExt) :bool {
|
||||
switch ($fileExt) {
|
||||
case 'png':
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'ico':
|
||||
case 'gif':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user