0

before i submittd i have this message

Notice: Undefined index: upload in C:\xampp\htdocs\art-legend\12\up\up.php on line 15

Notice: Undefined index: upload in C:\xampp\htdocs\art-legend\12\up\up.php on line 16

Notice: Undefined index: upload in C:\xampp\htdocs\art-legend\12\up\up.php on line 17

Notice: Undefined index: upload in C:\xampp\htdocs\art-legend\12\up\up.php on line 18

Notice: Undefined index: upload in C:\xampp\htdocs\art-legend\12\up\up.php on line 19

Notice: Undefined index: submit in C:\xampp\htdocs\art-legend\12\up\up.php on line 21

<!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>
Parag Tyagi
  • 8,780
  • 3
  • 42
  • 47
Foda
  • 58
  • 1
  • 7
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – j08691 Apr 18 '14 at 18:31

1 Answers1

0

Since $_FILES* are outside the if, it is getting executed before the form submission. Hence add those inside your 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);
}
Parag Tyagi
  • 8,780
  • 3
  • 42
  • 47