Skip to content

Commit

Permalink
Improved attachment error messaging, reverted change that removes att…
Browse files Browse the repository at this point in the history
…achment name field. Fixes issues #1 and #21
  • Loading branch information
jaronkk committed Mar 6, 2012
1 parent ad92dad commit 2d1e0af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
8 changes: 8 additions & 0 deletions ajax_forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,14 @@
<table class='noBorder' style='width:310px; margin:10px 15px;'>

<tr>
<td style='vertical-align:top;text-align:left;'><label for='shortName'><b>Name:</b></label></td>
<td>
<input type='text' class='changeInput' id='shortName' name='shortName' value = '<?php echo $attachment->shortName; ?>' style='width:230px' /><span id='span_error_shortName' class='smallDarkRedText'></span>
</td>
</tr>

<tr>

<td style='vertical-align:top;text-align:left;border:0px;'><label for='attachmentTypeID'><b>Type:</b></label></td>
<td style='vertical-align:top;text-align:left;border:0px;'>

Expand Down
11 changes: 10 additions & 1 deletion ajax_processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 "<div id=\"error\">There was a problem saving your file to $target_path. Please ensure your attachments directory is writable.</div>";
}

}
Expand Down
65 changes: 23 additions & 42 deletions js/forms/attachmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@



createUploader();

});

Expand All @@ -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(" <font color='red'>File name is already being used...</font>");
return false;
}else if (response == "2"){
} else if (response == "2"){
exists = "2";
fileName="";
$("#div_file_message").html(" <font color='red'>File name may not contain special characters - ampersand, single quote, double quote or less than/greater than characters</font>");
return false;
}else{
exists = "";
} else if (response == "3"){
exists = "3";
$("#div_file_message").html(" <font color='red'>The attachments directory is not writable.</font>");
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("<img src='images/paperclip.gif'>" + fileName + " successfully uploaded.");
$("#div_uploadFile").html("");
}else{
$("#div_file_message").html("<font color='red'>" . fileName + " was not successfully uploaded. Please make sure the /attachments/ directory exists and is writable.</font>");
fileName='';
if (exists == ""){
var errorMessage = $(response).filter('#error');
if (errorMessage.size() > 0) {
$("#div_file_message").html("<font color='red'>" + errorMessage.html() + "</font>");
} else {
$("#div_file_message").html("<img src='images/paperclip.gif'>" + fileName + " successfully uploaded.");
}

}
}
});

Expand Down

0 comments on commit 2d1e0af

Please sign in to comment.