<?php

// ============
include("../../../php_crud/my_class.php");
$obj = new my_class();
// ============


session_start();
if (isset($_FILES["file"]["type"])) {
    $return = array();
    $validextensions = array("xlsx", "xls");
    $temporary = explode(".", $_FILES["file"]["name"]);
    $file_extension = end($temporary);
    if ((($_FILES["file"]["type"] == "application/vnd.ms-excel") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") ) && ($_FILES["file"]["size"] < 10000000)//Approx. 100kb files can be uploaded.
            && in_array($file_extension, $validextensions)) {
        if ($_FILES["file"]["error"] > 0) {
            $return[] = "Error";
            $return[] = $_FILES["file"]["error"];
        } else {
            $new_file_name = date('Ymdhis') . rand(1000, 999999) . $_FILES['file']['name'];
            $sourcePath = $_FILES['file']['tmp_name']; // Storing source path of the file in a variable
            $targetPath = "./Excel_Sheet/" . $new_file_name; // Target path where file is to be stored
            move_uploaded_file($sourcePath, $targetPath); // Moving Uploaded file


            include('file_read_by_phpexel.php');

            $return['design'] = $design_details;
            $return['invalid_id'] = '<strong> Invalid id : </strong>  <span style="color:red">' . trim($invalid_id!==''?$invalid_id:0, ',') . '</span>';
            $return['valid_id'] = trim($valid_id, ',');
            $return['duplicate_id'] = '<strong>Duplicate Id : </strong> <span style="color:#6FB3E0  ">' . trim($duplicat_string!==''?$duplicat_string:0, ',') . '</span>';
            ;
            $return['status'] = "Success";
            $return['File_NAME'] = $new_file_name;
            if(is_file($targetPath)) unlink($targetPath) ;
        }
    } else {
        $return['status'] = "Error";
        $return['message'] = "Invalid file Size or Type";
    }
    echo json_encode($return);
}
?>