<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn,$zdb);
$zyear = right($zdb, 4);

if (isset($_REQUEST['evouchno'])) {
    $vouchno = $_POST["evouchno"];
    $leadvouch = $_POST["eleadvouch"];
    $srno = $_POST["esrno"];
    $esupplier = $_POST["esupplier"];
    
    $getimg = mysqli_query($conn,"SELECT * FROM `ledgupload` WHERE vouchno='$vouchno' and `leadvouch`='$leadvouch' and `srno`='$srno' and `supplier`='$esupplier'")or die(mysqli_query($conn,));
    $img = mysqli_fetch_array($getimg);
    $imgpath1 = $img[imgpath];
    $rows = mysqli_num_rows($getimg);

    $dir = "../tlt/admin/ledger/";
    
    if ($imgpath1 == "") {
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if ($file == $vouchno . $leadvouch .  $srno . $esupplier. '.PDF') {
                        Echo "File Name :-" . $file;
//                        Echo "../tlt/admin/bill/" . $file;
                    } elseif ($file == $vouchno . $leadvouch .  $srno . $esupplier. '.PDF') {
                        Echo "File Name :-" . $file;
//                        Echo "../tlt/admin/bill/" . $file;
                    } else {
                        Echo $imgpath;
                    }
                }
                closedir($dh);
            }
        }
    } else {
        
        $imgpath = substr($imgpath1,20);
        
        Echo "File Name :-"  . $imgpath;
    }
}