예제 #1
0
<?php

require_once "Math.php";
require_once "File.php";
$job = !isset($_REQUEST["job"]) ? '' : trim($_REQUEST["job"]);
$evenNumbers = array();
$oddNumbers = array();
$fiboNumbers = array();
$file = array();
if ($job == "uploadFile") {
    $file = new FileData($_FILES["aNumbers"]);
    //assign data from file to $file object
    //get even, odd and fibonacci numbers from file and store in respective arrays
    $evenNumbers = $file->GetEvenNumbers();
    $oddNumbers = $file->GetOddNumbers();
    $fiboNumbers = $file->GetFibonacciNumbers();
    if (!isset($_SESSION['file'])) {
        $_SESSION['file'] = $file;
    }
}
$job = !isset($_GET["job"]) ? '' : trim($_GET["job"]);
if ($job == "exportnumbers") {
    //If a valid file was submitted with the submit button, then its details are saved in a session
    if (isset($_SESSION['file'])) {
        $file = $_SESSION['file'];
        $file->ExportNumbers($_SESSION["filename"] . ".csv");
        //call ExportNumbers function using the filename stored in a session and adding .csv as an extension
    }
}
if ($job == "reset") {
    session_destroy();