-3

I get following errors and I don't know why.

Notice: Undefined index: myfile in C:\xampp\htdocs\upload.php on line 3
Notice: Undefined index: myfile in C:\xampp\htdocs\upload.php on line 4
Notice: Undefined index: myfile in C:\xampp\htdocs\upload.php on line 5
Notice: Undefined index: myfile in C:\xampp\htdocs\upload.php on line 6
Notice: Undefined index: myfile in C:\xampp\htdocs\upload.php on line 7

pls help , i m a beginner... My code:

 <html>//this is index.html

 <form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="myfile">File limit 1MB<p>
    <input type="submit" value="Upload">
 </form>
 </html>

this is my upload.php script

<?php //this is my upload.php script    
$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];

$temp = $_FILES["myfile"]["tmp_name"]; 
$error = $_FILES["myfile"]["error"];//size  
if ($size > 1000000){
die("The file size is too big!");}

else
move_uploaded_file($temp, "uploaded/" .$name);//move upload file    
?>

1 Answers1

0

Maybe the following will be of some help?

The following code will upload gif, jpeg, jpg, png files into a folder called uploads.

Form Upload

<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

upload.php

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 200000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";


    if (file_exists("uploads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);

      }
    }
  }
else
  {
  echo "Invalid file";
  }
?> 

You might have to CHMOD the folder to 777 to allow the files to be written too.

Malcolm
  • 784
  • 3
  • 7
  • 20