1
0
mirror of https://github.com/Rouji/single_php_filehost.git synced 2025-04-04 16:39:34 +00:00

refactor out the "attachment" sending stuff

This commit is contained in:
Rouji 2021-08-29 23:35:15 +02:00
parent 707f6f720f
commit 3aeafc78c2

View File

@ -236,13 +236,20 @@ function purge_files() : void
print("Deleted $num_del files totalling $total_size MiB\n"); print("Deleted $num_del files totalling $total_size MiB\n");
} }
function send_text_file(string $filename, string $content) : void
{
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Length: '.strlen($content));
print($content);
}
// send a ShareX custom uploader config as .json // send a ShareX custom uploader config as .json
function send_sharex_config() : void function send_sharex_config() : void
{ {
$name = $_SERVER['SERVER_NAME']; $name = $_SERVER['SERVER_NAME'];
$site_url = CONFIG::SITE_URL(); $site_url = CONFIG::SITE_URL();
$filename = $name.'.sxcu'; send_text_file($name.'.sxcu', <<<EOT
$content = <<<EOT
{ {
"Name": "$name", "Name": "$name",
"DestinationType": "ImageUploader, FileUploader", "DestinationType": "ImageUploader, FileUploader",
@ -251,11 +258,7 @@ function send_sharex_config() : void
"FileFormName": "file", "FileFormName": "file",
"ResponseType": "Text" "ResponseType": "Text"
} }
EOT; EOT);
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Length: '.strlen($content));
print($content);
} }
// send a Hupl uploader config as .hupl (which is just JSON) // send a Hupl uploader config as .hupl (which is just JSON)
@ -263,19 +266,14 @@ function send_hupl_config() : void
{ {
$name = $_SERVER['SERVER_NAME']; $name = $_SERVER['SERVER_NAME'];
$site_url = CONFIG::SITE_URL(); $site_url = CONFIG::SITE_URL();
$filename = $name.'.hupl'; send_text_file($name.'.hupl', <<<EOT
$content = <<<EOT
{ {
"name": "$name", "name": "$name",
"type": "http", "type": "http",
"targetUrl": "$site_url", "targetUrl": "$site_url",
"fileParam": "file" "fileParam": "file"
} }
EOT; EOT);
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Length: '.strlen($content));
print($content);
} }
// print a plaintext info page, explaining what this script does and how to // print a plaintext info page, explaining what this script does and how to