summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar steering72532026-07-10 06:56:28 +0000
committerGravatar steering72532026-07-10 06:56:28 +0000
commit0eb037506367e6b985de87c8d73c6edb3a6a91ac (patch)
tree388aa3cbd35f9eb9da2b4883507128824f1d551e
parentsend response to client before sending notification (diff)
downloadhostfiles-0eb037506367e6b985de87c8d73c6edb3a6a91ac.tar.gz
hostfiles-0eb037506367e6b985de87c8d73c6edb3a6a91ac.tar.bz2
hostfiles-0eb037506367e6b985de87c8d73c6edb3a6a91ac.zip
silence some warnings and let some safe comparisons be loose
-rw-r--r--upload.php20
1 files changed, 15 insertions, 5 deletions
diff --git a/upload.php b/upload.php
index 5a0b4b9..95d1a66 100644
--- a/upload.php
+++ b/upload.php
@@ -15,6 +15,12 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST' && $_SERVER['REQUEST_METHOD'] != 'PUT')
$c_t = strtolower($_SERVER['HTTP_CONTENT_TYPE'] ?? '');
if ($c_t == 'multipart/form-data' || 0 === strpos($c_t, 'multipart/form-data;')) {
$FILES = remap_files();
+ if (!isset($FILES['file'])) {
+ header('Status: 406 Not Acceptable');
+ header('Content-Type: text/plain');
+ echo "You need to upload the file within the field name 'file' or 'file[]' if you want to use multipart/form-data.\n";
+ exit;
+ }
foreach ($FILES['file'] as $file) {
if (!is_uploaded_file($file['tmp_name'])) {
die_error("Not an uploaded file: $file[tmp_name]");
@@ -31,10 +37,12 @@ if ($c_t == 'multipart/form-data' || 0 === strpos($c_t, 'multipart/form-data;'))
die_error("Making folder $hash_str failed");
}
}
- if (FALSE === move_uploaded_file($file['tmp_name'], $real_filepath)) {
+ if (!move_uploaded_file($file['tmp_name'], $real_filepath)) {
die_error("Renaming uploaded file $file[tmp_name] to $real_filepath failed");
}
- symlink($real_filepath, $filepath);
+ if (!file_exists($filepath)) {
+ symlink($real_filepath, $filepath);
+ }
echo UPLOAD_URL . $filename . "\n";
fastcgi_finish_request();
send_notification("[hostfil.es] $_SERVER[REMOTE_ADDR] uploaded $file[full_path] $file[type] -> https://g.hostfil.es/$filename");
@@ -43,7 +51,7 @@ if ($c_t == 'multipart/form-data' || 0 === strpos($c_t, 'multipart/form-data;'))
$in_fh = fopen('php://input', 'r');
$tmp_path = tempnam(UPLOAD_DIR, '.up-');
$out_fh = fopen($tmp_path, 'w');
- if (FALSE === $out_fh) {
+ if (!$out_fh) {
die_error("Couldn't open temporary file $tmp_path");
}
$hash = hash_init(HASH_ALGO);
@@ -57,7 +65,7 @@ if ($c_t == 'multipart/form-data' || 0 === strpos($c_t, 'multipart/form-data;'))
$size += $fwrite_status;
}
fclose($in_fh);
- if (FALSE === fclose($out_fh)) {
+ if (!fclose($out_fh)) {
die_error("Closing temporary file $tmp_path failed");
}
$hash_str = hash_final($hash);
@@ -76,7 +84,9 @@ if ($c_t == 'multipart/form-data' || 0 === strpos($c_t, 'multipart/form-data;'))
die_error("Renaming temporary file $tmp_path to $real_filepath failed");
}
}
- symlink($real_filepath, $filepath);
+ if (!file_exists($filepath)) {
+ symlink($real_filepath, $filepath);
+ }
echo UPLOAD_URL . $filename . "\n";
fastcgi_finish_request();
send_notification("[hostfil.es] $_SERVER[REMOTE_ADDR] uploaded $_SERVER[PATH_INFO] $c_t -> https://g.hostfil.es/$filename");