Fix file upload size limits and toast messages on failure

This commit is contained in:
ilham_gmail
2026-06-11 19:43:52 +07:00
parent 0593d25080
commit 3b62f71946
4 changed files with 34 additions and 13 deletions
+1
View File
@@ -1,6 +1,7 @@
server {
listen 80;
server_name localhost;
client_max_body_size 10M;
# 1. Landing Page Utama
location / {
+4
View File
@@ -15,4 +15,8 @@ RUN rm -f /var/www/html/uploads && mkdir -p /var/www/html/uploads
# Set ownership and permissions for uploads directory
RUN chown -R www-data:www-data /var/www/html && chmod -R 775 /var/www/html/uploads
# Increase PHP upload and post size limits
RUN echo "upload_max_filesize = 10M" > /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size = 10M" >> /usr/local/etc/php/conf.d/uploads.ini
EXPOSE 80
+25 -13
View File
@@ -1883,6 +1883,7 @@ function openEdit(id){
payload.assistance_notes = null;
}
(async function(){
let updateSuccess = false;
try{
const respUpdate = await fetch('src/api/update_lokasi.php',{method:'POST',headers:buildHeaders(),body:JSON.stringify(payload),credentials:'same-origin'});
const jrUpdate = await respUpdate.json().catch(()=>null);
@@ -1890,7 +1891,7 @@ function openEdit(id){
const reason = jrUpdate && jrUpdate.error ? jrUpdate.error : 'unknown';
showToast('Gagal menyimpan perubahan: ' + reason, 'error', 6000);
} else {
try{ showToast('Perubahan tersimpan', 'success', 2600); }catch(e){}
updateSuccess = true;
// optimistically update marker on the map so UI reflects change immediately
try{
const idStr = String(id);
@@ -1915,19 +1916,30 @@ function openEdit(id){
}catch(e){}
}
}catch(e){ console.error('update failed', e); showToast('Gagal menyimpan perubahan: ' + (e && e.message ? e.message : e), 'error', 6000); }
// use captured file from modal submit
if(file){
try{
const fdata = new FormData(); fdata.append('file', file); fdata.append('id', id);
const resp = await fetch('src/api/upload_photo.php',{method:'POST',headers:buildHeaders(null),body:fdata,credentials:'same-origin'});
const jr = await resp.json().catch(()=>null);
if(!jr || !jr.success){
const reason = jr && (jr.error || (jr.last_error && jr.last_error.message)) ? (jr.error || jr.last_error.message) : 'unknown';
showToast('Gagal mengunggah foto: ' + reason, 'error', 7000);
} else {
showToast('Foto berhasil diunggah', 'success', 3000);
if(updateSuccess){
let uploadSuccess = true;
if(file){
try{
const fdata = new FormData(); fdata.append('file', file); fdata.append('id', id);
const resp = await fetch('src/api/upload_photo.php',{method:'POST',headers:buildHeaders(null),body:fdata,credentials:'same-origin'});
const jr = await resp.json().catch(()=>null);
if(!jr || !jr.success){
uploadSuccess = false;
const reason = jr && (jr.error || (jr.last_error && jr.last_error.message)) ? (jr.error || jr.last_error.message) : 'unknown';
showToast('Gagal mengunggah foto: ' + reason, 'error', 7000);
} else {
showToast('Foto berhasil diunggah', 'success', 3000);
}
}catch(e){
uploadSuccess = false;
console.error('upload failed',e);
showToast('Gagal mengunggah foto: ' + (e && e.message ? e.message : e), 'error', 7000);
}
}catch(e){ console.error('upload failed',e); showToast('Gagal mengunggah foto: ' + (e && e.message ? e.message : e), 'error', 7000); }
}
if(uploadSuccess){
showToast('Perubahan tersimpan', 'success', 2600);
}
}
loadData();
})();
+4
View File
@@ -9,4 +9,8 @@ COPY . /var/www/html/
# Set ownership and permissions
RUN chown -R www-data:www-data /var/www/html
# Increase PHP upload and post size limits
RUN echo "upload_max_filesize = 10M" > /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size = 10M" >> /usr/local/etc/php/conf.d/uploads.ini
EXPOSE 80