上传音频的未定义索引 - WAMP

时间:2014-01-20 12:54:02

标签: php upload wamp

我一直在尝试将文件上传到服务器但是我收到了未定义的索引错误,如下所示:

Notice: Undefined index: uploadFile in D:\test\getfile.php on line 7
Notice: Undefined index: uploadFile in D:\test\getfile.php on line 8

这是我的index.php:

<html>
<head>
    <title>File Upload Form</title>
</head>
<body>
    This form allows you to upload a file to the server.<br>
    <form action="getfile.php" method="post"><br>
        Type (or select) Filename: <input type="file" name="uploadFile">
        <input type="submit" value="Upload File">
    </form>
</body>

这是getfile.php:

<html>
<head>
    <title>Process Uploaded File</title>
</head>
<body>
    <?php
        move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], 
               "../uploads/{$_FILES['uploadFile'] ['name']}")
    ?>
</body>

我从其他网站上获取了代码。这适用于他们的服务器。

这是在wamp。

3 个答案:

答案 0 :(得分:0)

您需要在表单标记中添加enctype='multipart/form-data'

  <form action="getfile.php" method="post" enctype='multipart/form-data'>

enctype属性指定用于将表单提交给服务器的内容类型(当方法的值为&#34; post&#34;)时。此属性的默认值为&#34; application / x-www-form-urlencoded&#34;。值&#34; multipart / form-data&#34;应与INPUT元素结合使用,键入=&#34; file&#34;。

index.php中的

<form action="getfile.php" method="post" enctype='multipart/form-data'><br>
    Type (or select) Filename: <input type="file" name="uploadFile">
    <input type="submit"  name="submit" value="Upload File">
</form>
getfile.php中的

<?php   
if(isset($_POST['submit'])){
       print_r($_FILES['uploadFile']);
        move_uploaded_file ($_FILES['uploadFile']['tmp_name'],    "../uploads/{$_FILES['uploadFile']['name']}");
  }
 ?>

答案 1 :(得分:0)

enctype='multipart/form-data'添加到表单声明中。

答案 2 :(得分:-2)

您可以设置类型(或选择)文件名:<input type="file" name="uploadFile">

name = uploadFile

并尝试上传$_FILES['uploadFile'] ['name'] ...

['name'] 更改为 ['uploadFile']

并添加enctype ='multipart / form-data