Mini Shell
<?php
$rootPath = realpath(dirname(__FILE__) . '/..');
require_once $rootPath . '/PortalMM/config/config.php'; // Use clean config file
session_start();
//require_once 'config/config.php';
$Grade = filter_input(INPUT_GET, 'Grade');
if ($Grade == 'All') {
$query = mysqli_query($conn, "SELECT * FROM student WHERE Status = 'Active' ORDER BY Level, Full_Name ASC");
} else {
$query = mysqli_query($conn, "SELECT * FROM student WHERE Level = '$Grade' AND Status = 'Active' ORDER BY Level, Full_Name ASC");
}
$num = mysqli_num_rows($query);
if ($num >0){
$delimeter = ",";
$filename = "Students_Notice_List_" . date('d-m-Y:i') . ".csv";
$f = fopen('php://memory', 'w');
$fields = array('Student_No', 'Full Name', 'Level', 'Email');
fputcsv($f, $fields, $delimeter);
while ($row = mysqli_fetch_assoc($query)) {
// Create line data with empty Marks field for user to fill
$lineData = array($row['Student_No'], $row['Full_Name'], $row['Level'], $row['email']);
fputcsv($f, $lineData, $delimeter);
}
fseek ($f, 0);
header ('Content-Type: txt/csv');
header('Content-Disposition: attachment; filename="' .$filename . '";');
fpassthru($f);
} else {
$_SESSION['failure'] = "Students list not found for the selected Class";
header('location: Notices.php');
}exit;
?>