以下是源代码,总是提示有错,页面分开执行就可以,总是没有获得$UploadAction的值。
<?php
if($UploadAction):
?>
<html>
<head><title>文件上载代码</title></head>
<body>
<?php
$TimeLimit=60;
$UploadAction=0;
set_time_limit($TimeLimit);
$uploaddir='..\\test\\uploadfile\\';
$uploadfile=$uploaddir.$_FILES['userfile']['name'];
$tmpfile=$_FILES['userfile']['tmp_name'];
$file_size=$_FILES['userfile']['size'];
$errno=$_FILES['userfile']['error'];
if(($tmpfile!="none")&&($tmpfile!=""))
{
if($file_size<1024)
  {
$strFileSize=(string)$file_size."字节";
  }
elseif($file_size<(1024*1024))
  {
$strFileSize=number_format((double)($file_size/1024),1)."KB";
  }
else
  {
$strFileSize=number_format((double)($file_size/(1024*1024)),1)."MB";
  }
if(!file_exists($uploadfile))
  {
if(move_uploaded_file($tmpfile,$uploadfile))
    {
echo "文件$uploadfile ($strFileSize)上载成功!";
    }
else
    {
echo "文件$uploadfile上载失败!(错误号:$errno)";
    }
  }
}
else
{
echo "你没有选择任何文件上载,或者上载的文件超过了$MAX_FILE_SIZE!";
}
set_time_limit(30);
?>
<br /><a href="upload2.php">返回</a>
</body>
</html>
<?php
else:
?>
<html>
<head><title>文件上载页面</title></head>
<body>
<table>
<center>
<form enctype="multipart/form-data" action="upload2.php" method="post" name="SubmitForm">
<input type="hidden" name="max_file_size" value="1000000">
<input type="hidden" name="UploadAction" value="1">
<tr><td><input name="userfile" type="file" size="30"></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="提交"></td>
<td><input name="reset" type="reset" value="重置"></td>
</tr>
<tr>
<?php
echo "$UploadAction";
?>
</tr>
</form>
</center>
</table>
</body>
</html>
<?
endif;
?>