PHP:尝试上传时未定义的索引

时间:2022-10-17 10:37:08

Just started to learn PHP codes, trying to test the upload function but end up failing. I am currently using WampServer and everything is local. Here are my codes. index.html:

刚开始学习PHP代码,尝试测试上传功能但最终失败了。我目前正在使用WampServer,一切都是本地的。这是我的代码。 index.html的:

<body>
  <div data-role='header'>
    <h1>Photo upload</h1>
  </div>

  <form action='upload_file.php' method='POST' enctype='multipart/form-data'>
    <input type='file' name='myfile'><p>
    <input type='submit' name='Upload' value='Upload'>
  </form>
</body>

upload_file.php:

<?php
echo $_FILES["myfile"]["name"];
?>

After selecting a file and pressing the 'Upload' button at index.html, it ends up giving 'Undefined Index' error.

选择文件并按下index.html上的“上传”按钮后,最终会出现“未定义索引”错误。

Any helps or advices are appreciated.

任何帮助或建议表示赞赏。

2 个解决方案

#1


0  

You have to follow right syntax for upload a file. Please see the tutorial

您必须按照正确的语法上传文件。请参阅教程

#2


0  

Check first if it's empty or not:

先检查它是否为空:

if (isset($_FILES["myfile"]["name"]))
{
    // File present
}

#1


0  

You have to follow right syntax for upload a file. Please see the tutorial

您必须按照正确的语法上传文件。请参阅教程

#2


0  

Check first if it's empty or not:

先检查它是否为空:

if (isset($_FILES["myfile"]["name"]))
{
    // File present
}