From 2d1e0af7d02d68a041c77c18b907417bcb136bd1 Mon Sep 17 00:00:00 2001 From: Jaron Kennel Date: Tue, 6 Mar 2012 10:54:20 -0500 Subject: [PATCH] Improved attachment error messaging, reverted change that removes attachment name field. Fixes issues #1 and #21 --- ajax_forms.php | 8 +++++ ajax_processing.php | 11 ++++++- js/forms/attachmentForm.js | 65 ++++++++++++++------------------------ 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/ajax_forms.php b/ajax_forms.php index df0a2f2..4cb5bbd 100644 --- a/ajax_forms.php +++ b/ajax_forms.php @@ -2114,6 +2114,14 @@ + + + + + +
+ +
diff --git a/ajax_processing.php b/ajax_processing.php index 139b575..d783cb1 100644 --- a/ajax_processing.php +++ b/ajax_processing.php @@ -658,7 +658,13 @@ $attachment = new Attachment(); $exists = 0; - + + if (!is_writable("attachments")) { + echo 3; + break; + } + + //first check that it doesn't have any offending characters if ((strpos($uploadAttachment,"'") > 0) || (strpos($uploadAttachment,'"') > 0) || (strpos($uploadAttachment,"&") > 0) || (strpos($uploadAttachment,"<") > 0) || (strpos($uploadAttachment,">") > 0)){ echo "2"; @@ -703,6 +709,9 @@ //this way we can edit the attachment directly on the server chmod ($target_path, 0766); echo "success uploading!"; + } else { + header('HTTP/1.1 500 Internal Server Error'); + echo "
There was a problem saving your file to $target_path. Please ensure your attachments directory is writable.
"; } } diff --git a/js/forms/attachmentForm.js b/js/forms/attachmentForm.js index 6f85495..a6be39b 100644 --- a/js/forms/attachmentForm.js +++ b/js/forms/attachmentForm.js @@ -69,7 +69,6 @@ - createUploader(); }); @@ -82,67 +81,49 @@ var exists = ''; //verify filename isn't already used function checkUploadAttachment (file, extension){ $("#div_file_message").html(""); - $.ajax({ - type: "GET", - url: "ajax_processing.php", - cache: false, - async: false, - data: "action=checkUploadAttachment&uploadAttachment=" + file, - success: function(response) { + $.ajax({ + type: "GET", + url: "ajax_processing.php", + cache: false, + async: false, + data: "action=checkUploadAttachment&uploadAttachment=" + file, + success: function(response) { + exists = ""; if (response == "1"){ exists = "1"; - fileName=""; $("#div_file_message").html(" File name is already being used..."); return false; - }else if (response == "2"){ + } else if (response == "2"){ exists = "2"; - fileName=""; $("#div_file_message").html(" File name may not contain special characters - ampersand, single quote, double quote or less than/greater than characters"); return false; - }else{ - exists = ""; + } else if (response == "3"){ + exists = "3"; + $("#div_file_message").html(" The attachments directory is not writable."); + return false; } - } - + + } }); } - - - - - function createUploader(){ - var uploader = new qq.FileUploader({ - element: document.getElementById('div_uploadFile'), - action: 'ajax_processing.php?action=uploadAttachment', - debug: true - }); - } - - - - - - - //do actual upload new AjaxUpload('upload_button', {action: 'ajax_processing.php?action=uploadAttachment', name: 'myfile', onChange : function (file, extension){checkUploadAttachment(file, extension);}, - onComplete : function(data){ + onComplete : function(data,response){ fileName=data; - //passed test - if ((exists == "") && (data != "")){ - $("#div_file_message").html("" + fileName + " successfully uploaded."); - $("#div_uploadFile").html(""); - }else{ - $("#div_file_message").html("" . fileName + " was not successfully uploaded. Please make sure the /attachments/ directory exists and is writable."); - fileName=''; + if (exists == ""){ + var errorMessage = $(response).filter('#error'); + if (errorMessage.size() > 0) { + $("#div_file_message").html("" + errorMessage.html() + ""); + } else { + $("#div_file_message").html("" + fileName + " successfully uploaded."); } - + } } });