I am trying to process an upload from another page. Once I submit, I get the error alert to ''please select an .CSV file' so it doesn't seem that the form name and id is being addressed. I do have other multiple forms on the same page none of which have the same submit name. Do I need to be more specific with '$_FILES['file']['name']' in the results form?
The Form
<div id="myModal6" class="modal">
<div class="modal-content-contribute">
<div class="modal-header">
<span class="close">×</span>
<h2>Upload Multiple lessons in .CSV format</h2>
</div>
<div class="modal-body-contribute">
<div id="message1"></div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Select CSV File</h3>
</div>
<div class="panel-body">
<div class="row" id="upload_area">
<form method="post" id="upload_form" enctype="multipart/form-data">
<div class="col-md-6" align="right">Select File</div>
<div class="col-md-6">
<input type="file" name="file" id="csv_file" />
</div>
<br /><br /><br />
<div class="col-md-12" align="center">
<input type="submit" name="upload_file" id="upload_file" class="btn btn-primary" value="Upload" />
</div>
</form>
</div>
<div class="table-responsive" id="process_area">
</div>
</div>
</div>
</div>
</div></div>';
Results Page
<?php
//upload.php
session_start();
$error = '';
$html = '';
if($_FILES['file']['name'] != '')
{
$file_array = explode(".", $_FILES['file']['name']);
$extension = end($file_array);
if($extension == 'csv')
{
$file_data = fopen($_FILES['file']['tmp_name'], 'r');
$file_header = fgetcsv($file_data);
$html .= '<table class="table table-bordered"><tr>';
for($count = 0; $count < count($file_header); $count++)
{
$html .= '
<th>
<select name="set_column_data" class="form-control set_column_data" data-column_number="'.$count.'">
<option value="">Set Count Data</option>
<option value="title">Title</option>
<option value="description">Lesson Description</option>
<option value="learningactivities">Activities</option>
<option value="materials">Materials</option>
<option value="healthobj">Health Objective</option>
<option value="nutriobj">Nutrition Objective</option>
<option value="opener">Opener</option>
<option value="closer">Closer</option>
<option value="adaptation">Adaptation</option>
<option value="recipe">Recipe</option>
</select>
</th>
';
}
$html .= '</tr>';
$limit = 0;
while(($row = fgetcsv($file_data)) !== FALSE)
{
$limit++;
if($limit < 6)
{
$html .= '<tr>';
for($count = 0; $count < count($row); $count++)
{
$html .= '<td>'.$row[$count].'</td>';
}
$html .= '</tr>';
}
$temp_data[] = $row;
}
$_SESSION['file_data'] = $temp_data;
$html .= '
</table>
<br />
<div align="right">
<button type="button" name="import" id="import" class="btn btn-success" disabled>Import</button>
</div>
<br />
';
}
else
{
$error = 'Only <b>.csv</b> file allowed';
}
}
else
{
$error = 'Please Select CSV File';
}
$output = array(
'error' => $error,
'output' => $html
);
echo json_encode($output);
?>