-2

test.php

<form action="test2.php" method="post" enctype="multipart/form-data">
        <input type="file" name="csv_file" accept=".csv">
        <button type="submit" name="submit" value="submit">submit</button>
</form>

test2.php

<?php
if(isset($_POST['submit'])){
    if ($_FILES["csv_file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["csv_file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["csv_file"]["name"] . "<br />";
  echo "Type: " . $_FILES["csv_file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["csv_file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["csv_file"]["tmp_name"];
  } 
}

?>

When I am submitting a csv file. The test2.php page is getting an error

undefined index: csv_file. Please Check.

Ayush Bansal
  • 51
  • 1
  • 8

1 Answers1

0

You are missing the enctype tag

<form method="post" enctype="multipart/form-data">

edit

in your case:

<form action="test2.php" method="post" enctype="multipart/form-data">
        <input type="file" name="csv_file" accept=".csv">
        <button type="submit" name="submit" value="submit">submit</button>
</form>
csskevin
  • 383
  • 2
  • 14