我在下面有一个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>
答案 0 :(得分:1)
找出<?php echo $result; ?>
实际呈现的内容。只需查看页面来源。
最有可能的是,0
。然后尝试找出move_uploaded_file
返回false的原因。可能在移动文件时发生了一些错误。