PHP - $ _FILES数组是空的 [英] PHP - $_FILES array is empty
问题描述
enctype
属性。其他形式/形式hanlders工作正常,所以临时目录必须是可写的。我出了主意。 我检查了后的值和 $ _ POST ['file']
exists和包含文件的名称。
这是我的表单和处理它的PHP。我缺少什么?
< form action ='orl_ftp.php'method ='post'enctype ='multipart / form -data'>
< table>
< tr>
< td>选取档案:< / td>
< td>< INPUT type ='file'id ='file'name ='file'>< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td>< INPUT type ='submit'name ='Submit'value ='Process'>< / td>
< / tr>
< / table>
< / form>
和相关的PHP代码。请注意,$ _FILES数组设置为,它只是空。
if(isset($ _ POST ['Submit'])){
$ upload_results =;
if(!isset($ _ FILES)){$ upload_results。=没有文件上传; }
if($ upload_results ==){
echo< pre>;
var_dump($ _ FILES);
出口;
...
$ b code $ pre
<在线101: < form method =解决方案 POSTaction =<?php echo $ _SERVER ['PHP_SELF'];?> />
$这是导致问题,浏览器保持这种形式打开,因此缺少 enctype
是问题。
示例:
< ?php
if(isset($ _ POST ['Submit'])){
$ upload_results =;
if(!isset($ _ FILES)){$ upload_results。=没有文件上传; }
if($ upload_results ==){
echo< pre>;
var_dump($ _ FILES);
出口;
}
}
?>
< form action =''method =post/>
< form action =''method ='post'enctype ='multipart / form-data'>
< table>
< tr>
< td>选取档案:< / td>
< td>< INPUT type ='file'id ='file'name ='file'>< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td>< INPUT type ='submit'name ='Submit'value ='Process'>< / td>
< / tr>
< / table>
< / form>
这不会发布任何档案。
Yes, the enctype
attribute is set. Other forms/form-hanlders work fine so the temp directory must be writable. I'm out of Ideas.
I checked the post values and $_POST['file']
exists and contains the name of the file.
Here is my form and the PHP that handles it. What am I missing?
<form action='orl_ftp.php' method='post' enctype='multipart/form-data'>
<table>
<tr>
<td>Choose File: </td>
<td><INPUT type='file' id='file' name='file'></td>
</tr>
<tr>
<td> </td>
<td><INPUT type='submit' name='Submit' value='Process'></td>
</tr>
</table>
</form>
And the relevant PHP code. Note that the $_FILES array is set, it's just empty.
if(isset($_POST['Submit'])){
$upload_results = "";
if(!isset($_FILES)){$upload_results .= "No files uploaded"; }
if($upload_results == ""){
echo "<pre>";
var_dump($_FILES);
exit;
// ...
}
}
解决方案 On line 101:
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" />
^
This is causing the issue, the browser it keeping this form open and therefore the missing enctype
is the issue. Remove or close this form properly.
Example:
<?php
if(isset($_POST['Submit'])){
$upload_results = "";
if(!isset($_FILES)){$upload_results .= "No files uploaded"; }
if($upload_results == ""){
echo "<pre>";
var_dump($_FILES);
exit;
}
}
?>
<form action='' method="post" />
<form action='' method='post' enctype='multipart/form-data'>
<table>
<tr>
<td>Choose File: </td>
<td><INPUT type='file' id='file' name='file'></td>
</tr>
<tr>
<td> </td>
<td><INPUT type='submit' name='Submit' value='Process'></td>
</tr>
</table>
</form>
This will not post any files.
这篇关于PHP - $ _FILES数组是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!