How do I fix this code to display the correct message after an upload?
<p>I have this code below where it checks to see if a file was uploaded successfully, unsuccessfully or canceled:</p>

<pre><code>  if (success === 1){ 
    result = '&lt;span class="imagemsg'+imagecounter+'"&gt;The file was uploaded successfully&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';       
    $('.listImage').eq(window.lastUploadImageIndex).append('&lt;div&gt;' + htmlEncode(imagefilename) + '&lt;button type="button" class="deletefileimage" image_file_name="' + imagefilename + '"&gt;Remove&lt;/button&gt;&lt;br/&gt;&lt;hr/&gt;&lt;/div&gt;');  
    displayInfo = replaceForm;       
  } 
  else if (success === 2){ 
    result = '&lt;span class="imagemsg'+imagecounter+'"&gt; The file upload was canceled&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;'; 
    displayInfo = updateForm;     
  } 
  else { 
    result = '&lt;span class="imagemsg'+imagecounter+'"&gt;There was an error during file upload&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;'; 
    displayInfo = updateForm;   
  }
</code></pre>

<p>But I have a JavaScript function where it outputs this below in the PHP script:</p>

<pre><code>&lt;script language="javascript" type="text/javascript"&gt; 
    window.top.stopImageUpload(&lt;?php echo $result ? 1 : 2; ?&gt;, '&lt;?php echo $_FILES['fileImage']['name'] ?&gt;'); 
&lt;/script&gt; 
</code></pre>

<p>Now if the file uploaded successfully, the correct message is displayed, if canceled, the correct mssage appear but the problem is that if the file fails to upload, then it displays the cancel message and not the error while uploading message. I tried to change part of the above code so it will be like this:</p>

<p><code>...&lt;?php echo $result ? 1 : 2 : 3 ?&gt;..</code></p>

<p>But this gives me an error. My question is how do I change the above code so that it will be able to output the correct message for when a file does not upload successfully?</p>
