我在下面有一个 javscript 函数,它根据结果显示一条消息:
function stopImageUpload(success){
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
}
else {
result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
}
return true;
}
下面的代码总是显示消息“文件已成功上传!”
<?php
$destination_path = str_replace("//", "/", $_SERVER['DOCUMENT_ROOT']."/")."ImageFiles";
$result = 0;
$target_path = $destination_path . basename( $_FILES['fileImage']['name']);
if(move_uploaded_file($_FILES['fileImage']['tmp_name'], $target_path)) {
$result = 1;
}
sleep(1);
?>
<script type='text/javascript' language='javascript'>
window.top.window.stopImageUpload(1);
</script>
但是,如果我将最后一行更改为下面的内容,则它始终会显示消息“文件上传期间出错!”。为什么会这样,如何解决它,以便根据结果显示正确的消息?
<script language="javascript" type="text/javascript">
window.top.window.stopImageUpload(<?php echo $result; ?>);
</script>