在我提交之前我有这个消息
注意:未定义的索引:在第15行的C:\ xampp \ htdocs \ art-legend \ 12 \ up \ up.php中上传
注意:未定义的索引:在第16行的C:\ xampp \ htdocs \ art-legend \ 12 \ up \ up.php中上传
注意:未定义的索引:在第17行的C:\ xampp \ htdocs \ art-legend \ 12 \ up \ up.php中上传
注意:未定义的索引:在第18行的C:\ xampp \ htdocs \ art-legend \ 12 \ up \ up.php中上传
注意:未定义的索引:在第19行的C:\ xampp \ htdocs \ art-legend \ 12 \ up \ up.php中上传
注意:未定义的索引:在第21行的C:\ xampp \ htdocs \ art-legend \ 12 \ up \ up.php中提交
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>Untitled Document</title>
</head>
<body>
<?
$dir_name = dirname(__FILE__)."/uploaded/";
$path = $_FILES['upload']['tmp_name'];
$name = $_FILES['upload']['name'];
$size = $_FILES['upload']['size'];
$type = $_FILES['upload']['type'];
$error = $_FILES['upload']['error'];
if($_POST['submit'])
{
move_uploaded_file($path,$dir_name.$name);
}
else
{
echo "error in uploaded";
}
?>
<form action="<? echo $PHP_SELF;?>" method="post" enctype="multipart/form-data">
<input type="file" name="upload" />
<input type="submit" name="submit" value="upload" />
</form>
</form>
</body>
</html>
答案 0 :(得分:0)
由于$_FILES*
位于if
之外,因此会在表单提交之前执行。因此,在if statement
-
if(isset($_POST['submit']))
{
$dir_name = dirname(__FILE__)."/uploaded/";
$path = $_FILES['upload']['tmp_name'];
$name = $_FILES['upload']['name'];
$size = $_FILES['upload']['size'];
$type = $_FILES['upload']['type'];
$error = $_FILES['upload']['error'];
move_uploaded_file($path,$dir_name.$name);
}