我在下面有这段代码,问题是它没有上传文件,并且底部的回调 javascript 函数没有显示结果。现在,在我输入 if isset ($_POST[fileImage'])... 代码和$_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
, 然后文件完美上传之前。但是使用这 2 段代码,它已经停止了上传。
所以我认为问题在于我使用的上面的代码放错了地方。如何将下面的代码正确放置在正确的位置以使上传重新开始工作?
以下是假设上传文件但失败的代码:
<?php
$result = 0;
if (isset($_POST['fileImage']) && ((($_FILES["fileImage"]["type"] == "image/gif")
|| ($_FILES["fileImage"]["type"] == "image/jpeg")
|| ($_FILES["fileImage"]["type"] == "image/pjpeg")
|| ($_FILES["fileImage"]["type"] == "image/jpg")
|| ($_FILES["fileImage"]["type"] == "image/png")
|| ($_FILES["fileImage"]["type"] == "image/tif"))){
if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
$parts = explode(".",$_FILES['fileImage']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;
while( file_exists("ImageFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileImage']['name'] = $base."_".$n.".".$ext;
move_uploaded_file($_FILES["fileImage"]["tmp_name"],
"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
}
else
{
move_uploaded_file($_FILES["fileImage"]["tmp_name"],
"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
}
?>
<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo $result;?>);
</script>
<?php
}
$_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
?>