<?php include('../core/connect.php');
$FileNo=$_GET['asin'];

//Use Mysql Query to find the 'full path' of file using $FileNo.
// I Assume $FilePaths as 'Full File Path'.
$result_resource=$dbh->query("select * from expenses where autoid='$FileNo'");
$row_resource=$result_resource->fetchObject();
$dave=$row_resource->attachment;

$filepath = 'uploads/' . $dave;

    if (file_exists($filepath)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . basename($filepath));
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize('uploads/' . $row_resource->attachment));
        readfile('uploads/' . $row_resource->attachment);
        // // Now update downloads count
        // $newCount = $file['downloads'] + 1;
        // $updateQuery = "UPDATE files SET downloads=$newCount WHERE id=$id";
        // mysqli_query($conn, $updateQuery);
        exit;
    }
?>