未定义的索引:文件。尝试了所有其他解决方案

时间:2014-10-15 07:10:58

标签: php

我有一个表单upload.php:

session_start();
<form action="../../banking/upload_file.php" method="post" enctype="multipart/form-data" id="bank">
    <br /><br />
    <label for="file">Select File:</label><br />
    <input type="file" name="file" id="file" /> 
    <input type="submit" name="submit" value="Upload" />
</form>

我有upload_file.php文件:

session_start();
$filsuc = 0;
if(isset($_REQUEST['submit'])){
if ($_FILES["file"]["error"] > 0)
  {
  $fil = $_FILES["file"]["name"];
  if($_FILES["file"]["error"] == 4)
    echo "<div align=center>Please ensure that you pick a file</div>";
  elseif($_FILES["file"]["error"] == 1)
    echo "<div align=center>File is too large, maximum limit is 2MB</div>";
  else
    echo "<div align=center>Error: " . $_FILES["file"]["error"] . "</div><br />";
  }
else
  {
  $filsuc = 1;
  $fil = $_FILES["file"]["name"];
  echo "<div align=center>";
  echo "<br>Thank you, the file has been stored in: " . "upload/" . $fil;
    echo"<br><br><br><input type=button onclick='location.href=\"banking.php?fil=$fil\"' value=\"Click here to continue\">";
    echo "</div>";
    //echo "<br><br>Click <a href=\"banking.php?fil=$fil\">here</a> to continue.";

  }


      move_uploaded_FILES($_FILES["file"]["tmp_name"],
      "upload/" . $fil);
      echo "<div align=center>";
      echo " <br>OR ";
      echo"<br><br><br><input type=button onclick='location.href=\"upload.php\"' value=\"Click here to go back to start\">";
       if($filsuc == 1)
        echo "<br><br><img src=\"pics/fileuploadblur.jpg\" />";
      echo "</div>";
     // echo "<br><br><br><a href=\"upload.php\">Back to start</a> ";   

}   

如果我注释掉if(isset($_REQUEST['submit'])),我会收到错误Undefined index:file。否则我会得到一个空白的结果页面。我假设我的数据没有通过我的upload_file.php文件。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

move_uploaded_FILES($_FILES["file"]["tmp_name"],
      "upload/" . $fil);

<强>&GT;将此功能更改为以下功能

move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $fil);

答案 1 :(得分:0)

尝试撰写

$fil = $_FILES["file"]["name"];

 after 

 if(isset($_REQUEST['submit'])){