krokos.net.pl
Masz wyłączoną obsługę javascript, niektóre funkcje na stronie mogą działać nieprawidłowo
28.03.2024
Aniela, Kasrot, Sonia, Jan, Antoni, Krzesisław, Sykstus
dziś jest : 88 dzień roku wschód słońca o : 5:30 , zachód o : 18:09 koniec roku za : 277 dni
Programowanie PHP - Różnica Zawartości Wybranych Folderów
Klasa pozwala na sprawdzenie różnicy zawartości wybranych folerów pod względem nazw plików. Opcje pozwalają na wybór wyświetlania zwróconej różnicy plików jak również wybór rodzaju porównania pomiędzy folderami. Klasa przydatna szczególnie przy porównywaniu duzej ilości często bardzo podobnych nazw w folderach.
CODE : php
  1. /**
  2.  * difference in the names of files and folders from selected folders
  3.  * copyright : (c) 2014 Andrzej Krokos
  4.  * version PHP : 5
  5.  * author : shreker983@gmail.com
  6.  * licence : GPL
  7.  *
  8. */
  9.  
  10. class diff_data
  11. {
  12.     function set_data($directory) // set data
  13.     {
  14.         $this->directory = $directory;
  15.     }    
  16.    
  17.     function dir_to_array($directory) // listing folder
  18.     {
  19.         if (file_exists($directory))
  20.         {
  21.             $data = array();
  22.             if ($handle = opendir($directory))
  23.             {
  24.                 while (false !== ($entry = readdir($handle)))
  25.                 {
  26.                     if ($entry == '.' || $entry == '..')
  27.                     {
  28.                         continue;
  29.                     }
  30.                     $data[] = $entry;
  31.                 }
  32.                 closedir($handle);
  33.                 return $data;
  34.             }
  35.         }
  36.         else
  37.         {
  38.             echo '<div style="font-family:arial; text-align:center; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">error: could not open dir "'.$this->directory.'" !</div>';
  39.             return false;
  40.         }
  41.     }
  42.  
  43.     function get_data($type, $folder1, $folder2) // get manipulation data
  44.     {
  45.         $mdata = ($type == 'ai') ? array_intersect($this->dir_to_array($folder1), $this->dir_to_array($folder2)) : array_diff($this->dir_to_array($folder1), $this->dir_to_array($folder2));
  46.         return $mdata;
  47.     }
  48.  
  49.     function show_data($ret, $type, $folder1, $folder2) // show data
  50.     {
  51.         $cdata = count($this->get_data($type, $folder1, $folder2));
  52.         if ($ret == 'd')
  53.         {
  54.             foreach($this->get_data($type, $folder1, $folder2) as $f) // names to data
  55.             {
  56.                 echo '<strong>'.$f.'</strong><em> ('.(is_file($folder1.'/'.$f) ? 'file' : 'folder').')</em><br />';
  57.             }
  58.         }
  59.         else
  60.         {
  61.             echo '<pre>';
  62.             var_dump($this->get_data($type, $folder1, $folder2)); // names to array
  63.             echo '</pre>';
  64.         }
  65.         echo '<div style="font-weight:bold;'.(($cdata == 0) ? ' text-align:center; color:red;' : ' text-align:right;').' padding:10px 5px 5px 5px;">'.(($cdata == 0) ? 'no data !' : 'all : '.$cdata.' pcs.').'</div>';
  66.     }
  67.  
  68.     function get_form() // show form
  69.     {
  70.         $post_data = array('folder1', 'folder2', 'type', 'show');
  71.         foreach ($post_data as $name)
  72.         {
  73.             $_POST[$name] = isset($_POST[$name]) ? $_POST[$name] : '';
  74.         }
  75.  
  76.         echo '<div style="vertical-align:left; padding: 5px 5px 5px 5px;">';
  77.         echo '<fieldset>';
  78.         echo '<legend>difference in the names of files and folders from selected folders</legend>';        
  79.         if (!isset($_POST['nfolder']))
  80.         {
  81.             echo '<form name="" action="" method="post">';
  82.             echo '<p><label for="name">folder (root) :</label><select class="" name="folder1" id="folder1" style="vertical-align:middle; width:250px; margin-left:5px;">';
  83.             echo '<option value="" selected="selected">select ...</option>';
  84.             foreach(glob($this->directory.'*', GLOB_ONLYDIR) as $dir1)
  85.             {
  86.                 echo '<option value="'.$dir1.'" '.(($dir1 == $_POST['folder1']) ? 'selected' : '').'>'.$dir1.'</option>'; // select folder - root
  87.             }
  88.             echo '</select></p>';
  89.             echo '<p><label for="name">folder (comp.) :</label><select class="" name="folder2" id="folder2" style="vertical-align:middle; width:250px; margin-left:5px;">';
  90.             echo '<option value="" selected="selected">select ...</option>';
  91.             foreach(glob($this->directory.'*', GLOB_ONLYDIR) as $dir2)
  92.             {
  93.                 echo '<option value="'.$dir2.'" '.(($dir2 == $_POST['folder2']) ? 'selected' : '').'>'.$dir2.'</option>'; // select folder - comp.
  94.             }
  95.             echo '</select></p>';
  96.             echo '<p><label for="name">compare :</label><select class="" name="type" style="vertical-align:middle; width:200px; margin-left:5px;">';
  97.             echo '<option value="" selected="selected">select ...</option>';
  98.             $type = array('ai' => 'repeated files', 'ad' => 'difference files');
  99.             foreach($type as $vt => $namet)
  100.             {            
  101.                 echo '<option value="'.$vt.'"'.($vt == $_POST['type'] ? ' selected="selected"' : '').'>'.$namet.'</option>'; // select
  102.             }
  103.             echo '</select></p>';
  104.             echo '<p><label for="name">data (return) :</label><select class="" name="show" style="vertical-align:middle; width:200px; margin-left:5px;">';
  105.             echo '<option value="" selected="selected">select ...</option>';
  106.             $show = array('a' => 'names to array', 'd' => 'names to data');
  107.             foreach($show as $vs => $names)
  108.             {            
  109.                 echo '<option value="'.$vs.'"'.($vs == $_POST['show'] ? ' selected="selected"' : '').'>'.$names.'</option>';
  110.             }
  111.             echo '</select></p>';
  112.             echo '<div style="text-align:center; padding:5px 5px 5px 5px;"><input type="submit" name="nfolder" value="SELECT" class="przycisk" onclick="return confirm('are you sure?')" style="margin-left:5px; vertical-align:middle;" /></div>';
  113.             echo '</form>';
  114.         }
  115.         else
  116.         {
  117.             if (empty($_POST['folder1']) || empty($_POST['folder2']) || empty($_POST['type']) || empty($_POST['show']))
  118.             {
  119.                 echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">select data !</div>';
  120.             }
  121.             else if (!file_exists($_POST['folder1']))
  122.             {
  123.                 echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">incorrect folder path !</div>';
  124.             }
  125.             else if (!file_exists($_POST['folder2']))
  126.             {
  127.                 echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">incorrect folder path !</div>';
  128.             }
  129.             else if ($_POST['folder1'] == $_POST['folder2'])
  130.             {
  131.                 echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">both paths are identical !</div>';
  132.             }        
  133.             else if (!in_array($_POST['type'], array('ai', 'ad')))
  134.             {
  135.                 echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">select the type of comparison !</div>';
  136.             }
  137.             else if (!in_array($_POST['show'], array('a', 'd')))
  138.             {
  139.                 echo '<div style="text-align:center; font-family:arial; color:red; font-size:12px; font-weight:bold; padding:5px 5px 5px 5px;">select the type for displaying result !</div>';
  140.             }
  141.             else
  142.             {
  143.                 echo '<div style="vertical-align:left; padding:5px 0px 0px 0px;">';
  144.                 $this->show_data($_POST['show'], $_POST['type'], $_POST['folder1'], $_POST['folder2']);
  145.                 echo '</div>';
  146.             }
  147.             echo '<div style="vertical-align:left; padding: 5px 5px 5px 5px;">';
  148.             echo '<form action="'.$_SERVER['HTTP_REFERER'].'" method="post">';
  149.             echo '<div style="text-align:center; padding:5px 5px 5px 5px;"><input type="submit" name="back" value="BACK" /></div>';
  150.             echo '</form>';
  151.             echo '</div>';
  152.         }
  153.         echo '<div style="text-align:center; font-family:verdana; color:black; font-size:10px; font-weight:normal; padding:5px 5px 5px 5px;">design by sid &copy; 2004 - '. date('Y').'</div>';    
  154.         echo '</fieldset>';
  155.         echo '</div>';
  156.     }
  157. }
  158.  
  159. // example
  160. $dd = new diff_data();
  161. $dd->set_data('./');
  162. $dd->get_form();
propozycja przykładowego css :
CODE : css
  1. body
  2. {
  3.     background-color: #ffffff;                
  4.     font-family: arial;
  5.     font-size: 12px;
  6.     line-height: 1.3;
  7. }
  8. label
  9. {
  10.     font-family: arial;
  11.     font-size: 12px;
  12.     font-weight: bold;
  13.     color: #000000;
  14.     width: 100px;
  15.     float: left;
  16.     text-align: right;
  17.     margin-right: 5px;
  18.     display: block;
  19. }
  20. .submit input
  21. {
  22.     margin-left: 5px;
  23. }
  24. input
  25. {
  26.     color: #781351;
  27.     background: #fee3ad;
  28.     border: 1px solid #781351;
  29. }
  30. .submit input
  31. {
  32.     color: #000;
  33.     background: #ffa20f;
  34.     border: 2px outset #d7b9c9;
  35. }
  36. fieldset
  37. {
  38.     border: 1px solid #781351;
  39.     width: 400px;
  40. }
  41. legend
  42. {
  43.     color: #fff;
  44.     background: #ffa20c;
  45.     border: 1px solid #781351;
  46.     padding: 2px 6px;
  47. }
pobierz plik ( rozmiar : 2.28 kB )
ocena : 4.4(oddano : 10 głosów)
online : 1 użytkownik, dziś odwiedziło : 51 osób
Zgodnie z nowelizacją ustawy o Prawie Telekomunikacyjnym informujemy, że strona krokos.net.pl w swoim działaniu korzysta z zapisywanych informacji w postaci ciasteczek (ang. cookies).
Pajacyk - Nakarm Głodne Dziecko
powered by scms © 2004 - 2024 design by sid