<?php
if ( !defined('_JEXEC') )  define( '_JEXEC', 1 );
if(!defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

/**
 *
 * @package  MediaLibrary
 * @copyright 2021 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru); Rob de Cleen(rob@decleen.com);
 * Homepage: https://ordasoft.com
 * @version: 4.6 Free
 * @license GNU General Public license version 2 or later; see LICENSE.txt
 *
 */


$cover_path = is_dir('../../..'.$_POST['cover_path']);

if($cover_path){
    $asin_isbn = trim($_POST['asin_isbn']);
    $files = scandir('../../..'.$_POST['cover_path']);//Получить список файлов и каталогов

    foreach($files as $element)
    {
    $f_arr = preg_split('/(\.|_)/U', $element);
    
        if (array_search($asin_isbn , $f_arr)!==false){
        $img_type = array('jpeg','jpg','png','bmp','gif');
            $type     = strtolower($f_arr[count($f_arr)-1]);

            if (array_search($type,$img_type)!==false){      
                $path_valid = $_POST['cover_path'].$element;
                    echo $path_valid;
                        exit();

            }
         }
    }   
}else{
echo "1"; //folder not found
}

