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 { server {
listen 80; listen 80;
server_name localhost; server_name localhost;
client_max_body_size 10M;
# 1. Landing Page Utama # 1. Landing Page Utama
location / { 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 # Set ownership and permissions for uploads directory
RUN chown -R www-data:www-data /var/www/html && chmod -R 775 /var/www/html/uploads 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 EXPOSE 80
+25 -13
View File
@@ -1883,6 +1883,7 @@ function openEdit(id){
payload.assistance_notes = null; payload.assistance_notes = null;
} }
(async function(){ (async function(){
let updateSuccess = false;
try{ try{
const respUpdate = await fetch('src/api/update_lokasi.php',{method:'POST',headers:buildHeaders(),body:JSON.stringify(payload),credentials:'same-origin'}); 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); const jrUpdate = await respUpdate.json().catch(()=>null);
@@ -1890,7 +1891,7 @@ function openEdit(id){
const reason = jrUpdate && jrUpdate.error ? jrUpdate.error : 'unknown'; const reason = jrUpdate && jrUpdate.error ? jrUpdate.error : 'unknown';
showToast('Gagal menyimpan perubahan: ' + reason, 'error', 6000); showToast('Gagal menyimpan perubahan: ' + reason, 'error', 6000);
} else { } else {
try{ showToast('Perubahan tersimpan', 'success', 2600); }catch(e){} updateSuccess = true;
// optimistically update marker on the map so UI reflects change immediately // optimistically update marker on the map so UI reflects change immediately
try{ try{
const idStr = String(id); const idStr = String(id);
@@ -1915,19 +1916,30 @@ function openEdit(id){
}catch(e){} }catch(e){}
} }
}catch(e){ console.error('update failed', e); showToast('Gagal menyimpan perubahan: ' + (e && e.message ? e.message : e), 'error', 6000); } }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){ if(updateSuccess){
try{ let uploadSuccess = true;
const fdata = new FormData(); fdata.append('file', file); fdata.append('id', id); if(file){
const resp = await fetch('src/api/upload_photo.php',{method:'POST',headers:buildHeaders(null),body:fdata,credentials:'same-origin'}); try{
const jr = await resp.json().catch(()=>null); const fdata = new FormData(); fdata.append('file', file); fdata.append('id', id);
if(!jr || !jr.success){ const resp = await fetch('src/api/upload_photo.php',{method:'POST',headers:buildHeaders(null),body:fdata,credentials:'same-origin'});
const reason = jr && (jr.error || (jr.last_error && jr.last_error.message)) ? (jr.error || jr.last_error.message) : 'unknown'; const jr = await resp.json().catch(()=>null);
showToast('Gagal mengunggah foto: ' + reason, 'error', 7000); if(!jr || !jr.success){
} else { uploadSuccess = false;
showToast('Foto berhasil diunggah', 'success', 3000); 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(); loadData();
})(); })();
+4
View File
@@ -9,4 +9,8 @@ COPY . /var/www/html/
# Set ownership and permissions # Set ownership and permissions
RUN chown -R www-data:www-data /var/www/html 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 EXPOSE 80