Advertisement
NFL

Untitled

NFL
Jun 3rd, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.29 KB | None | 0 0
  1. <?php
  2.  
  3. class Renamer {
  4.  
  5.     private $_ftpHost; //фтп хост
  6.     private $_ftpPath; //путь к папке на сервере
  7.     private $_ftpLogin; //логин пользователя фтп
  8.     private $_ftpPwd; //пароль фтп
  9.     private $_ftpLink = null; //идентификатор соединения
  10.    
  11.     private $_strTrArray = array(
  12.         'а'=>'a',
  13.         'б'=>'b',
  14.         'в'=>'v',
  15.         'г'=>'h',
  16.         'д'=>'d',
  17.         'е'=>'e',
  18.         'ж'=>'zh',
  19.         'з'=>'z',
  20.         'и'=>'y',
  21.         'й'=>'y',
  22.         'к'=>'k',
  23.         'л'=>'l',
  24.         'м'=>'m',
  25.         'н'=>'n',
  26.         'о'=>'o',
  27.         'п'=>'p',
  28.         'р'=>'r',
  29.         'с'=>'s',
  30.         'т'=>'t',
  31.         'у'=>'u',
  32.         'ф'=>'f',
  33.         'ц'=>'ts',
  34.         'ч'=>'ch',
  35.         'ш'=>'sh',
  36.         'щ'=>'shch',
  37.         'ь'=>'',
  38.         'ы'=>'y',
  39.         'э'=>'e',
  40.         'ю'=>'yu',
  41.         'я'=>'ja',
  42.        
  43.        
  44.         'А'=>'A',
  45.         'Б'=>'B',
  46.         'В'=>'V',
  47.         'Г'=>'H',
  48.         'Д'=>'D',
  49.         'Е'=>'E',
  50.         'Ж'=>'ZH',
  51.         'З'=>'Z',
  52.         'И'=>'Y',
  53.         'Й'=>'Y',
  54.         'К'=>'K',
  55.         'Л'=>'L',
  56.         'М'=>'M',
  57.         'Н'=>'N',
  58.         'О'=>'O',
  59.         'П'=>'P',
  60.         'Р'=>'R',
  61.         'С'=>'S',
  62.         'Т'=>'T',
  63.         'У'=>'U',
  64.         'Ф'=>'F',
  65.         'Х'=>'KH',
  66.         'Ц'=>'TS',
  67.         'Ч'=>'SCH',
  68.         'Ш'=>'SH',
  69.         'Щ'=>'SHCH',
  70.         'Ь'=>'',
  71.         'Ы'=>'Y',
  72.         'Э'=>'E',
  73.         'Ю'=>'YU',
  74.         'Я'=>'JA',
  75.        
  76.     );
  77.    
  78.  
  79.     public function __construct() {
  80.         return $this;
  81.     }
  82.  
  83.     public function connect($host, $login, $pwd) {
  84.         if (!empty($host)) {
  85.             $this->_ftpHost = $host;
  86.             $this->_ftpLogin = $login;
  87.             $this->_ftpPwd = $pwd;
  88.  
  89.  
  90.             try {
  91.                 $link = ftp_connect($this->_ftpHost);
  92.                 $result = ftp_login($link, $this->_ftpLogin, $this->_ftpPwd);
  93.                 $this->_ftpLink = $link;
  94.                 if (!$result) {
  95.                     throw new Exception("Не могу залогиниться на фтп :(");
  96.                 }
  97.             } catch (Exception $e) {
  98.                 echo $e->getMessage();
  99.             }
  100.         } else {
  101.             exit("Не указан хост!");
  102.         }
  103.         return $this;
  104.     }
  105.     public function setDirectory($path) {
  106.         $this->_ftpPath = $path;
  107.         ftp_chdir($this->_ftpLink, $this->_ftpPath);
  108.         //
  109.         return $this;
  110.     }
  111.     public function translitFilename($replaceSpaces='') {
  112.        
  113.         $files = ftp_nlist($this->_ftpLink, $this->_ftpPath);
  114.         array_shift($files);
  115.         array_shift($files);
  116.         foreach ($files as $value) {
  117.             echo '<br>'.str_replace(' ', $replaceSpaces, strtr($value, $this->_strTrArray));
  118.            // ftp_rename($this->_link, $value, str_replace(' ', $replaceSpaces, strtr($value, $this->_strTrArray)));
  119.         }
  120.         //var_dump(ftp_nlist($this->_link, $this->_path));
  121.     }
  122.  
  123. }
  124. $renamer = new Renamer();
  125. $renamer->connect('195.64.154.190', 'beinstyl', '-c%5+Vk;==T_');
  126. $renamer->setDirectory('/public_html/downloads/catalog/gallery/big/');
  127. $renamer->translitFilename();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement