文件上传php $ _FILES未定义索引错误 [英] file upload php $_FILES undefined index error
本文介绍了文件上传php $ _FILES未定义索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
$name = $_FILES["file"]["name"];
//$size = $_FILES['file']['size']
//$type = $_FILES['file']['type']
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
if (isset ($name)) {
if (!empty($name)) {
$location = 'uploads/';
if (move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
我收到'通知:未定义索引'错误消息。 enctype包含在表单标签中,所以我无法弄清楚它是什么..任何人都可以帮助我吗?
i get an 'Notice: Undefined index' error message. The enctype is included in the form tag so i can't figure out what it is.. can anyone help me out??
推荐答案
如果没有上传任何内容并且isset测试有点无用,则第一个分配会抛出警告..
The first assignment throws an warning, if nothing is uploaded and the isset test is a little bit useless..
您可以按如下方式更改代码
You can change your code as follows
<?php
if (isset($_FILES["file"]["name"])) {
$name = $_FILES["file"]["name"];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
if (!empty($name)) {
$location = 'uploads/';
if (move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
?>
<form action="test.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
这篇关于文件上传php $ _FILES未定义索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文