Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Renamer {
- private $_ftpHost; //фтп хост
- private $_ftpPath; //путь к папке на сервере
- private $_ftpLogin; //логин пользователя фтп
- private $_ftpPwd; //пароль фтп
- private $_ftpLink = null; //идентификатор соединения
- private $_strTrArray = array(
- 'а'=>'a',
- 'б'=>'b',
- 'в'=>'v',
- 'г'=>'h',
- 'д'=>'d',
- 'е'=>'e',
- 'ж'=>'zh',
- 'з'=>'z',
- 'и'=>'y',
- 'й'=>'y',
- 'к'=>'k',
- 'л'=>'l',
- 'м'=>'m',
- 'н'=>'n',
- 'о'=>'o',
- 'п'=>'p',
- 'р'=>'r',
- 'с'=>'s',
- 'т'=>'t',
- 'у'=>'u',
- 'ф'=>'f',
- 'ц'=>'ts',
- 'ч'=>'ch',
- 'ш'=>'sh',
- 'щ'=>'shch',
- 'ь'=>'',
- 'ы'=>'y',
- 'э'=>'e',
- 'ю'=>'yu',
- 'я'=>'ja',
- 'А'=>'A',
- 'Б'=>'B',
- 'В'=>'V',
- 'Г'=>'H',
- 'Д'=>'D',
- 'Е'=>'E',
- 'Ж'=>'ZH',
- 'З'=>'Z',
- 'И'=>'Y',
- 'Й'=>'Y',
- 'К'=>'K',
- 'Л'=>'L',
- 'М'=>'M',
- 'Н'=>'N',
- 'О'=>'O',
- 'П'=>'P',
- 'Р'=>'R',
- 'С'=>'S',
- 'Т'=>'T',
- 'У'=>'U',
- 'Ф'=>'F',
- 'Х'=>'KH',
- 'Ц'=>'TS',
- 'Ч'=>'SCH',
- 'Ш'=>'SH',
- 'Щ'=>'SHCH',
- 'Ь'=>'',
- 'Ы'=>'Y',
- 'Э'=>'E',
- 'Ю'=>'YU',
- 'Я'=>'JA',
- );
- public function __construct() {
- return $this;
- }
- public function connect($host, $login, $pwd) {
- if (!empty($host)) {
- $this->_ftpHost = $host;
- $this->_ftpLogin = $login;
- $this->_ftpPwd = $pwd;
- try {
- $link = ftp_connect($this->_ftpHost);
- $result = ftp_login($link, $this->_ftpLogin, $this->_ftpPwd);
- $this->_ftpLink = $link;
- if (!$result) {
- throw new Exception("Не могу залогиниться на фтп :(");
- }
- } catch (Exception $e) {
- echo $e->getMessage();
- }
- } else {
- exit("Не указан хост!");
- }
- return $this;
- }
- public function setDirectory($path) {
- $this->_ftpPath = $path;
- ftp_chdir($this->_ftpLink, $this->_ftpPath);
- //
- return $this;
- }
- public function translitFilename($replaceSpaces='') {
- $files = ftp_nlist($this->_ftpLink, $this->_ftpPath);
- array_shift($files);
- array_shift($files);
- foreach ($files as $value) {
- echo '<br>'.str_replace(' ', $replaceSpaces, strtr($value, $this->_strTrArray));
- // ftp_rename($this->_link, $value, str_replace(' ', $replaceSpaces, strtr($value, $this->_strTrArray)));
- }
- //var_dump(ftp_nlist($this->_link, $this->_path));
- }
- }
- $renamer = new Renamer();
- $renamer->connect('195.64.154.190', 'beinstyl', '-c%5+Vk;==T_');
- $renamer->setDirectory('/public_html/downloads/catalog/gallery/big/');
- $renamer->translitFilename();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement