I'm exploring the file upload and text parsing capabilities of PHP, but my first step is buggy, and I can't figure it out. The goal of the code is to display a form to upload a text, and then display the value of the corresponding $_FILES array. However, it doesn't work - it runs without error but doesn't display print_r($_FILES['upload']). What am I missing?
This is my Index_txtParsing file:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>test</title>
</head>
<body>
<form enctype="multipart/form-data" class="Txt_upload" method='POST' action='index_txtParsing.php'>
<label for="file">Enter upload here:</label>
<input type='file' name='upload'/>
<input type='submit' name='submit' value="upload here"/>
</form>
</body>
</html>
<?php
if(isset($_POST['upload'])){
$upload=$_POST['upload'];
print_r($_FILES['upload']);
}else{
$upload="unknown";
}
?>
EDIT: After incorporating the recommendations below, this code works:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>test</title>
</head>
<body>
<form enctype="multipart/form-data" class="Txt_upload" method='POST' action='index_txtParsing.php'>
<label for="file">Enter upload here:</label>
<input type='file' name='upload'/>
<input type='submit' name='submit' value="upload here"/>
</form>
</body>
</html>
<?php
if(isset($_FILES['upload'])){
echo "Value of FILES['upload'] ";
print_r($_FILES['upload']);
echo "<br/>";
}else{
}
?>