<?php
if(isset($_POST['filePath']) && isset($_POST['target_valu_new'])){
require_once('../config.php');
 ?>
 <div class="col-4 col-sm-4 col-md-2 col-lg-2  mb-2">
 	<div class="attachment-preview clickableText" data-bs-dismiss="modal" data-target="<?php echo $_POST['target_valu_new'] ?>" data-url="<?php echo $site_domain ?>uploads/<?php echo $_POST['filePath'] ?>">
 		<div class="thumbnail">
      <?php
      $tt_file_type = isImage($_POST['filePath']);
      if ($tt_file_type == 'image') {
        ?>
        <div class="centered">
          <img src="<?php echo $site_domain ?>uploads/<?php echo $_POST['filePath'] ?>" alt="<?php echo $_POST['filePath'] ?>">
        </div>
        <?php
      }else {
        ?>
        <div class="text-center">
          <span class="p-1 mb-2 bg-primary text-white d-block"><i class="fs-6 ri-file-warning-line"></i></span>
          <span class="fs-6"><?php echo $_POST['filePath'] ?></span>
        </div>
        <?php
      }
      ?>
 		</div>
 	</div>
 </div>
 <script type="text/javascript">
 $(document).ready(function() {
     $('.clickableText').on('click', function() {
         var urlValue = $(this).data('url');
         var targetInputId = $(this).data('target');
         $(targetInputId).val(urlValue);
         var Preview_Image_Div = targetInputId+'_Preview';
         $(Preview_Image_Div).attr('src', urlValue)
     });
 });
 </script>

 <?php
} 
 ?>
