我试图建立一个上传表单并且我得到了通知 (!)注意:未定义的索引:第19行的C:\ wamp32 \ www \ game \ upload.php中的myfile 我正在使用的代码是:
<?php
include("config.php");
session_start();
$_SESSION['uname']="123";
$uname = $_SESSION['uname'];
$upload = <<<EOT
Welcome, $uname<p>
Upload your image:
<form action='upload.php' method='POST' ectype='multipart/form-data'>
File:<input type='file' name='myfile'><input type='submit' name='submit' value='Upload!'>
</form>
EOT;
if (isset($_POST['submit']))
{
//get file attributes
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name)
{
//start upload process
$location = "upload/$name";
move_uploaded_file($tmp_name, $location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE uname='$uname'");
die("Your avatar has been uploaded! <a href='view.php'>Home</a>");
}
else
die("Please select a file!");
}
echo ($upload);
?>
我试过那样的
$ name =(isset($ _ FILES ['myfile'] ['name'])); $ tmp_name =(isset($ _ FILES ['myfile'] ['tmp_name']));
在这种情况下,它不会显示通知,但它不会完成工作。
答案 0 :(得分:3)
ectype='multipart/form-data'
应该是
enctype='multipart/form-data'
<form action='upload.php' method='POST' enctype='multipart/form-data'>