upload form update

This commit is contained in:
NottyNoz 2023-03-26 18:12:22 -04:00 committed by Shish
parent 909e54b1e2
commit 56a60a9ec1

View file

@ -43,6 +43,8 @@ class UploadTheme extends Themelet
$tl_enabled = ($config->get_string(UploadConfig::TRANSLOAD_ENGINE, "none") != "none");
$max_size = $config->get_int(UploadConfig::SIZE);
$max_kb = to_shorthand_int($max_size);
$max_total_size = parse_shorthand_int(ini_get('post_max_size')) - 102400; //leave room for http request data
$max_total_kb = to_shorthand_int($max_total_size);
$upload_list = $this->h_upload_list_1();
$form = SHM_FORM("upload", "POST", true, "file_upload");
@ -58,6 +60,10 @@ class UploadTheme extends Themelet
TD(["colspan"=>"5"], INPUT(["name"=>"source", "type"=>"text"]))
),
$upload_list,
TR(
TD(["colspan"=>$tl_enabled ? 2 : 4,"id"=>"upload_size_tracker"], ""),
TD(["colspan"=>2], ""),
),
TR(
TD(["colspan"=>"6"], INPUT(["id"=>"uploadbutton", "type"=>"submit", "value"=>"Post"]))
),
@ -65,7 +71,62 @@ class UploadTheme extends Themelet
);
$html = emptyHTML(
$form,
SMALL("(Max file size is $max_kb)")
SMALL("(Max file size is $max_kb)"),
SMALL(BR(), "(Max total size is $max_total_kb)"),
rawHTML("<script>
function fileSize(size){
var i = Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}
function updateTracker(){
var size = 0;
var upbtn = $(\"#uploadbutton\")[0];
var tracker = $(\"#upload_size_tracker\")[0];
var lockbtn = false;
$(\"input[name*='data'][id!='data[]']\").each(function(_,n){
var cancelbtn = $(\"div[name='cancel\"+n.name+\"']\")[0];
var toobig = false;
if (n.files.length){
cancelbtn.style.visibility = 'visible';
for (var i = 0; i<n.files.length; i++){
size += n.files[i].size;
if (n.files[i].size > $max_size){
toobig = true;
}
}
if (toobig){
lockbtn = true;
n.style = 'color:red';
}else{
n.style = 'color:initial';
}
}else{
n.style = 'color:initial';
cancelbtn.style.visibility = 'hidden';
}
});
if (size){
tracker.innerText = 'Total: ' + fileSize(size);
if (size > $max_total_size){
lockbtn = true;
tracker.style = 'color:red';
}else{
tracker.style = 'color:initial';
}
}else{
tracker.innerText = '';
}
upbtn.disabled = lockbtn;
}
window.onload = function(){
$(\"input[name*='data'][id!='data[]']\").change(function(){
updateTracker();
});
updateTracker();
}
</script>")
);
$page->set_title("Upload");
@ -96,7 +157,7 @@ class UploadTheme extends Themelet
for ($i=0; $i<$upload_count; $i++) {
$upload_list->appendChild(
TR(
TD(["colspan"=>$tl_enabled ? 2 : 4], INPUT(["type"=>"file", "name"=>"data{$i}[]", "accept"=>$accept, "multiple"=>true])),
TD(["colspan"=>$tl_enabled ? 2 : 4], DIV(["name"=>"canceldata{$i}[]","style"=>"display:inline;margin-right:5px;font-size:15px;visibility:hidden;","onclick"=>"$(\"input[name='data{$i}[]']\")[0].value='';updateTracker();"],""), INPUT(["type"=>"file", "name"=>"data{$i}[]", "accept"=>$accept, "multiple"=>true])),
$tl_enabled ? TD(["colspan"=>"2"], INPUT(["type"=>"text", "name"=>"url{$i}"])) : emptyHTML(),
TD(["colspan"=>"2"], INPUT(["type"=>"text", "name"=>"tags{$i}", "class"=>"autocomplete_tags", "autocomplete"=>"off"])),
)
@ -203,7 +264,7 @@ class UploadTheme extends Themelet
)
));
$html = emptyHTML(
$html = html_entity_decode((string)emptyHTML(
P(
"Replacing Post ID $image_id",
BR(),
@ -213,7 +274,7 @@ class UploadTheme extends Themelet
BR(),
$form,
SMALL("(Max file size is $max_kb)"),
);
));
$page->set_title("Replace Post");
$page->set_heading("Replace Post");
@ -260,6 +321,8 @@ class UploadTheme extends Themelet
$max_size = $config->get_int(UploadConfig::SIZE);
$max_kb = to_shorthand_int($max_size);
$max_total_size = parse_shorthand_int(ini_get('post_max_size')) - 102400; //leave room for http request data
$max_total_kb = to_shorthand_int($max_total_size);
// <input type='hidden' name='max_file_size' value='$max_size' />
$form = SHM_FORM("upload", "POST", true);
@ -275,6 +338,7 @@ class UploadTheme extends Themelet
["class"=>'mini_upload'],
$form,
SMALL("(Max file size is $max_kb)"),
SMALL(BR(),"(Max total size is $max_total_kb)"),
NOSCRIPT(BR(), A(["href"=>make_link("upload")], "Larger Form"))
);
}