Abhishek
Abhishek

Reputation: 351

php undefined index coming on uploading file with ['name']

    <form action='' method='post'>
    <input type="file" class="form-control" name="kk">
    <input type="submit" class="form-control" name="submit">
    </form>
    <?php
    if(isset($_POST['submit'])){

    echo $_FILES["kk"]["name"]; 

    }
    ?>

hi,i'm new to php,In this code undefined index kk coming on uploading file,i just want the file name...please help me out

Upvotes: 0

Views: 49

Answers (2)

B. Desai
B. Desai

Reputation: 16436

You need to pass enctype="multipart/form-data" when you have to upload file

<form action='' method='post' enctype="multipart/form-data">
    <input type="file" class="form-control" name="kk">
    <input type="submit" class="form-control" name="submit">
    </form>
    <?php
    if(isset($_POST['submit'])){

    echo $_FILES["kk"]["name"]; 

    }
    ?>

Upvotes: 1

user1405631
user1405631

Reputation:

add enctype="multipart/form-data" to form tag

Upvotes: 3

Related Questions