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"];
}
}
?>
当我提交csv文件时。 test2.php页面出错了
未定义的索引:csv_file。 请检查。
答案 0 :(得分:0)
您缺少enctype标记
<form method="post" enctype="multipart/form-data">
在你的情况下:
<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>