0

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?

1
  • Looking at the above code, yes it must either be 1 or 2. However, because you're only using it as a Boolean value, you should refactor it. Commented Sep 24, 2012 at 16:26

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.