<?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 = $_REQUEST['evouchno'];
    $passport = $_REQUEST['epassno'];
    $getimg = mysqli_query($conn,"SELECT * FROM `leadpdf` WHERE `vouchno`='$vouchno'")or die(mysqli_query($conn,));
    $img = mysqli_fetch_array($getimg);
    $imgpath = $img[pdfpath];
    $rows = mysqli_num_rows($getimg);

    $dir = "../tlt/admin/pdf/";

    if ($imgpath == "") {
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if ($file == $vouchno . '.PDF') {
                        Echo "../tlt/admin/pdf/" . $file;
                    }elseif($file == $vouchno . '.PDF'){
                        Echo "../tlt/admin/pdf/" . $file;
                    }else{
                        Echo $imgpath;
                    }
                }
                closedir($dh);
            }
        }
    }else{
        Echo $imgpath;
    }
}