Ad

Notice: Undefined Index: Myfile

- 1 answer

Iam trying to build an upload form and Iam getting notices ( ! ) Notice: Undefined index: myfile in C:\wamp32\www\game\upload.php on line 19 and the code I am using is:

    <?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);
    ?>

I have tried like that

$name = (isset($_FILES['myfile']['name'])); $tmp_name = (isset($_FILES['myfile']['tmp_name']));

In this case it does not display notices but it does not do the work eather.

Ad

Answer

ectype='multipart/form-data'

should be

enctype='multipart/form-data'

<form action='upload.php' method='POST' enctype='multipart/form-data'>
Ad
source: stackoverflow.com
Ad