Reputation: 83
I have an ajax file uploader plugin (Max's File Uploader) where I copy and pasted the code and made some alterations.
Now below is a jQuery code where it measures if the file is successful, unsuccessful or cancelled:
function stopImageUpload(success, imagefilename){
var result = '';
imagecounter++;
var replaceForm = function(result) {
$(sourceImageForm).find('.imagef1_upload_form').html(result + '<label>Image File: <input name="fileImage" class="fileImage" type="file"/></label><br/><br/><label><input type="submit" name="submitImageBtn" class="sbtnimage" value="Upload" /></label><label><input type="button" name="imageClear" class="imageClear" value="Clear File"/></label>');
}
var updateForm = function(result) {
$(sourceImageForm).find('.imagef1_upload_form').find('.display_content_image').html(result);
}
var displayInfo;
if (success === 1){
result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span><br/><br/>';
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
displayInfo = replaceForm;
}
else if (success === 2){
result = '<span class="imagemsg'+imagecounter+'"> The file upload was canceled</span><br/><br/>';
displayInfo = updateForm;
}
else {
result = '<span class="imagemsg'+imagecounter+'">There was an error during file upload</span><br/><br/>';
displayInfo = updateForm;
}
displayInfo(result);
)};
But I have a JavaScript function where it outputs this below in the PHP script:
<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');
</script>
What my question is, though, is that where it says 'true' or 'false' above, should this be 1 : 2 because I am measuring success of the files using numeric values and not string values?
Upvotes: 0
Views: 70
Reputation: 23208
Instead of using true
and false
you can use 1 and 2.
<script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result ? 1 : 2; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');</script>
Upvotes: 1