<?php
 function savePreview($imgstring, $filename, $zoom, $postfix){ //Создать превью
    $img = imagecreatefromstring($imgstring); 
    $width = imagesx($img);
    $height = imagesy($img);       
    $percent = $zoom;
    $newwidth = $width * $percent;
    $newheight = $height * $percent;
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    if(!$postfix){
        imagejpeg($thumb, 'images/preview/'.pathinfo($filename)["filename"].'.jpg');
    }
    else{
        imagepng($thumb, 'images/preview/'.pathinfo($filename)["filename"].$postfix.'.png');        
    }
    imagedestroy($img);
 }

 function getFileNames($foldername)
 {
    $filenames = scandir($foldername);
    $names = [];
    unset($filenames[0], $filenames[1]);
    sort($filenames);
    foreach($filenames as $filename){
     array_push($names, $filenames);
    }
    return $filenames;
 }

// function checkState($filename, $auto){
//     $data = date("y-m-d h:i:s");        
//     $dir = "images/tmp/";
//     $filename_tmp = $dir.$filename."_tmp";  
//     $file_opened = 0;           
//     if(file_exists($filename_tmp)){
//         $strStart = file_get_contents($filename_tmp); 
//         $dteStart = new DateTime($strStart);
//         $dteEnd   = new DateTime($data);
//         $interval  = $dteStart->diff($dteEnd);
//         if ( $interval->y >= 1
//         or $interval->m >= 1
//         or $interval->d >= 1
//         or $interval->h >= 1    
//         or $interval->i >= 0
//     ){
//             file_put_contents($filename_tmp, $data);                            
//         }else{
//             $file_opened = 1;       
//         }
//     }else if($auto){
//         file_put_contents($filename_tmp, $data);        
//     }
//     return $file_opened;
// }
?>