最近自学 php 在学习上传文件一课时遇到问题,代码如此:
upload.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上传文件</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-date">
<input type="file" name="myFile">
<input type="submit" value="提交">
</form>
</body>
</html>
upload.php:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>The Image</title>
</head>
<body>
<?php
$file=$_FILES['myFile'];
$fileName=$file['name'];
move_uploaded_file($file['tmp_name'],$fileName);
echo "<img src='$fileName'>";
?>
</body>
</html>
当运行时总提示 :
Notice: Undefined index: myFile in D:\xampp\htdocs\form\upload.php on line 15
没有被定义呢? 我是小白求指教,感激不尽!!!
PHP 写的没多大问题,但提示Undefined index说明上传文件出错,enctype="multipart/form-data"是data不是date.这个设置错了是不行的。