File "download-error-report.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/staff/download-error-report.php
File size: 1.19 KiB (1216 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
// Suppress all error output
error_reporting(0);
ini_set('display_errors', 0);

header('Content-Type: application/json');

try {
    if (!isset($_GET['file']) || empty($_GET['file'])) {
        http_response_code(400);
        echo json_encode([
            'status' => 'error',
            'message' => 'File parameter is required'
        ]);
        exit;
    }
    
    $filename = basename($_GET['file']); // Sanitize filename
    $filePath = '../../uploads/' . $filename;
    
    if (!file_exists($filePath)) {
        http_response_code(404);
        echo json_encode([
            'status' => 'error',
            'message' => 'Error report file not found'
        ]);
        exit;
    }
    
    // Set headers for file download
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header('Cache-Control: max-age=0');
    
    // Output the file
    readfile($filePath);
    
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'status' => 'error',
        'message' => 'Error downloading file: ' . $e->getMessage()
    ]);
}
?>













PHP File Manager