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

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

$filepath = 'uploadspic/' . $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('uploadspic/' . $row_trends->attachment));
        readfile('uploadspic/' . $row_trends->attachment);
        // // Now update downloads count
        // $newCount = $file['downloads'] + 1;
        // $updateQuery = "UPDATE files SET downloads=$newCount WHERE id=$id";
        // mysqli_query($conn, $updateQuery);
        exit;
    }
?>