<?php 
if($_POST[Submit]=="提交"){
$file=$_POST[file]; }   //取得文件域的值,并保存在变量 file 中,在下面的代码中显示变量file的值
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>获取文件域的值-php教程-www.dushuwu.net</title>
<style type="text/css">
<!--
.style1 {font-size: 14px}
.style2 {font-size: 12px}
-->
</style>
</head>
<body>
<table width="300" border="1" cellpadding="0" cellspacing="0">
  <tr align="center">
    <td height="25" colspan="2"><span class="style1">获取文件域的值</span></td>
  </tr>
  <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>">
  <tr>
    <td width="95" align="center"><span class="style2">上传:</span></td>
    <td width="200">
       <input name="file" type="file" id="file" size="15" maxlength="80">
    </td>
  </tr>
  <tr>
    <td align="center" class="style2">输出上传的值:</td>
    <td class="style2"><?php echo $file;?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="上传"></td>
  </tr>
  </form>
</table>
</body>
</html>这里的变量$file换成任务一个字符结果都出不来了

解决方案 »

  1.   

    <input type="file" ……在 $_FILES 中接收数据数组下表用''括起来更妥,另外依你的文件,上传后$_FILES['file']是个数组,,,调试可以var_dump打印判断
      

  2.   

    if($_POST[Submit]=="提交"){
    ==>
    if(isset($_POST[Submit])){还有确认你的环境支持段标记吗? 不支持的话用<?php echo $_SERVER['PHP_SELF'] ?>
    其实为空就是提交到本页面了。
      

  3.   

    至少需将 if($_POST[Submit]=="提交"){
    改为 if($_POST[Submit]=="上传"){
      

  4.   

    <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>"  enctype="multipart/form-data">
    加上这个
      

  5.   

      <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>"> 这个里面缺少了东西哦。。 应该是这样:<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">这样你的form提交后才有数据的。。