我在下面有这段代码,它检查文件是否上传成功、不成功或取消:
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;
}
但我有一个 JavaScript 函数,它在 PHP 脚本中输出以下内容:
<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo $result ? 1 : 2; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');
</script>
现在,如果文件上传成功,则会显示正确的消息,如果取消,则会出现正确的消息,但问题是如果文件上传失败,则显示取消消息,而不是上传消息时的错误。我试图改变上面的代码的一部分,所以它会是这样的:
...<?php echo $result ? 1 : 2 : 3 ?>..
但这给了我一个错误。我的问题是如何更改上述代码,以便在文件未成功上传时输出正确的消息?