$ _FILES未定义索引:文件 [英] $_FILES undefined index : file

查看:84
本文介绍了$ _FILES未定义索引:文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
    echo $_FILES['file']['error'];
?>

<form action="uploads.php" method = "POST">
    <input  name="file" type="file" enctype="multipart/form-data"><br>
    <input type="Submit" value="Submit"/>
</form>

此代码出现undefined index file错误.

我该怎么办?

这只是我尝试实现的代码的简化版本.在原始代码中,我使用了isset()函数.但是在那种情况下,我没有任何输出!

This is just the shortened version of the code that I am trying to implement. In the original code I have used isset() function. However in that case I am not getting any output!

推荐答案

正确的方法是:

<?php
if(isset($_POST['submit'])){
echo $_FILES['file']['error'];
}
?>

<form action="uploads.php" method = "POST" enctype="multipart/form-data">
    <input  name="file" type="file"><br>
    <input type="Submit" value="Submit" name='submit'/>
</form>

您在提交表单之前回显了"$_FILES['file']['error']".提交表单后回显输入类型的文件值或其他值.

You are echoing "$_FILES['file']['error']" before form submit. echo input type file value or something after form submission.

这篇关于$ _FILES未定义索引:文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆