file upload php $_FILES undefined index error(文件上传 php $_FILES 未定义索引错误)
本文介绍了文件上传 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 未定义索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:文件上传 php $_FILES 未定义索引错误


猜你喜欢
- PHP Count 布尔数组中真值的数量 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01