2014-06-17 03:44
浏览 15


i am using the get method to upload the file and when i write the $_FILES["file"]["name"]then it gives the error Undefined index: file but if i use the post method then it works fine. How can i access the file name or file type.Here is the code of first page.

<form action="upload2.php" method="GET"
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">

Here is the code of second page


图片转代码服务由CSDN问答提供 功能建议

我使用 get 方法上传文件,当我写 $ _ FILES [“file”] [“name”] 然后它给出错误 Undefined index:file 但是如果我使用 post 方法那么它的工作原理 精细。 如何访问文件名或文件类型。这是第一页的代码。

 &lt; html&gt; 
&lt; body&gt; 
&lt; form action =“upload2  .php“method =”GET“
enctype =”multipart / form-data“&gt; 
&lt; label for =”file“&gt;文件名:&lt; / label&gt; 
&lt; input type =”file“name =” 文件“id =”file“&gt;&lt; br&gt; 
&lt; input type =”submit“name =”submit“value =”Submit“&gt; 
&lt; / form&gt; 
&lt; / body&gt; 
&lt; /  html&gt; 


 $ _FILES [“  file“] [”name“]; 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxia527680
    dongxia527680 2014-06-17 04:04

    Files cannot be uploaded through a GET request. You need to use POST.

    The PHP manual's definition for $_FILES:

    "An associative array of items uploaded to the current script via the HTTP POST method."

    (Emphasis mine)

    点赞 评论
  • doutenglou6588
    doutenglou6588 2014-06-17 04:08

    Files uploaded through a form using POST method It will always end up in PHP's $_FILES superglobal. while you are using GET method to do that but its not possible as per my knowledge at this condition PHP's $_FILES is not present that's why you are getting error Undefined index: file.

    点赞 评论