My application reads a csv file and convert it to pdf. For this I have the frontend in html to load the file. I would like to know how do I show the user a message stating that the file is invalid. The file will be invalid when the number of columns in the loaded csv file is greater or less than 9.
<!DOCTYPE html>
<html lang="en">
<head>
</style>
<meta charset="UTF-8">
<title>Site Report</title>
</head>
<body>
<h3> Site Report </h3>
</span></span>
<form action="" method="post" enctype="multipart/form-data">
<labeL>
<span>Choose CSV file:</span>
</span></span>
<input type="file" accept="text/csv" name="userfile"/>
</labeL>
<p> </p>
<input type="submit" name="action" value="Upload"/>
</form>
<?php
if(isset($_POST['action']) && $_POST['action']=='Upload'):
$userFile=$_FILES['userfile'];
$name = $userFile['name'];
$tmp = $userFile ['tmp_name'];
$extension=explode('.', $name);
$ext=end($extension);
$newName =md5($name).'.'.$ext;
$newName= str_replace(' $name ','$name','uploadFile').'.'.$ext;
$userMessage="File uploaded successfuly ";
if(empty($userFile)):
echo 'Select an file to upload';
else:
if(move_uploaded_file($tmp, 'uploads/'.$newName)):
echo $userMessage;
else:
echo 'Error';
endif;
endif;
endif;
?>
<form action="download.php" method="post">
<p>
</p>
<input type="submit" name="submit" value="Download PDF File" />
</form>
</body>
</html>