I have this html form:
<form method="post" action="upload_prospects" enctype="multipart/form-data">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><input type="file" name="file" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="submit" value="Save / Upload" /></td>
</tr>
</table>
</form>
Then i use this PHP code to upload the data:
<?php
if(isset($_POST["submit"])) {
echo 'upload';
$display='';
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
echo '<h3>File '.$_FILES["file"]["name"].' uploaded successfully</h3>';
//Import uploaded file to Database
$handle = fopen($_FILES['file']['tmp_name'], "r");
fgetcsv($handle);
//then loop through each row
while(($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$value = $data[13];
$first_arr = explode(' ',trim($value));
$first = $first_arr[0];
$last_arr = explode(' ', $value);
$last = array_pop($last_arr);
preg_match('/'.preg_quote($first).'(.*?)'.preg_quote($last).'/is', $value, $match);
$display.= $data[1].'<br>';
$display.= 'title: '.$first.'<br>';
$display.= 'forename: '.$match[1].'<br>';
$display.= 'surname: '.$last.'<br>';
$sql="INSERT into prospects (industry, company, address1, town, postcode, county, phone, title, forename, surname, contact_position, email) values ('".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[8])."', '".addslashes($first)."', '".addslashes($match[1])."', '".addslashes($last)."', '".addslashes($data[14])."', '".addslashes($data[16])."'); ";
$display.= $sql.'<br><br>';
$rs=mysql_query($sql,$conn) or die(mysql_error());
}
}
echo 'Done';
//echo $display;
}
?>
I have tested this and i can see in chrome the selected file being uploaded, however it don't even see the echo 'upload';
text on my page.
however, if i just click submit without selecting a file, i see the echo 'upload';
and the echo 'Done';