114 lines
4.2 KiB
PHP
114 lines
4.2 KiB
PHP
|
<?php
|
|||
|
|
|||
|
class class_SYSTEM{
|
|||
|
function __construct(){
|
|||
|
}
|
|||
|
/**
|
|||
|
* Загрузка файла
|
|||
|
* @param $name
|
|||
|
* @param string $ddir
|
|||
|
* @param int $replacefile
|
|||
|
* @return array
|
|||
|
*/
|
|||
|
public function uploadfile($name, $ddir = '', $replacefile = 0){
|
|||
|
GLOBAL $ST;
|
|||
|
$out = array();
|
|||
|
$file = '';
|
|||
|
//$uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/upload/';
|
|||
|
$uploaddir = 'upload/';
|
|||
|
if ($ddir != '') $uploaddir .= $ddir . '/';
|
|||
|
if (!file_exists($uploaddir)) mkdir($uploaddir, 0777, true);
|
|||
|
if (isset($_FILES[$name])) {
|
|||
|
$pi = pathinfo($_FILES[$name]['name']);
|
|||
|
$fx = $pi['extension'];
|
|||
|
$fn = $pi['filename'];
|
|||
|
|
|||
|
if(isset($_SESSION['user'])){
|
|||
|
$rf = $_SESSION['user']['id'].'_'.$this->translit($fn) . '.' . $fx;
|
|||
|
}else{
|
|||
|
$rf = '0_'.$this->translit($fn) . '.' . $fx;
|
|||
|
}
|
|||
|
$uploadfile = $uploaddir . $rf;
|
|||
|
if($replacefile==0) {
|
|||
|
if (file_exists($uploadfile)) {
|
|||
|
if (isset($_SESSION['user'])) {
|
|||
|
$rf = $_SESSION['user']['id'] . '_' . $this->translit($fn) . '_' . mt_rand(1000, 9999) . '.' . $fx;
|
|||
|
} else {
|
|||
|
$rf = '0_' . $this->translit($fn) . '_' . mt_rand(1000, 9999) . '.' . $fx;
|
|||
|
}
|
|||
|
}
|
|||
|
$uploadfile = $uploaddir . $rf;
|
|||
|
}
|
|||
|
$fisset=false;
|
|||
|
if($replacefile==2) {//2ой режим если есть файл то не грузим его
|
|||
|
if(file_exists($uploadfile)) $fisset=true;
|
|||
|
$out['file'] = $rf;
|
|||
|
$out['path'] = $uploaddir;
|
|||
|
$out['err'] = 0;
|
|||
|
$out['msg'] = 'файл существовал';
|
|||
|
}
|
|||
|
if(!$fisset){
|
|||
|
if (move_uploaded_file($_FILES[$name]['tmp_name'], $uploadfile)) {
|
|||
|
$out['file'] = $rf;
|
|||
|
$out['path'] = $uploaddir;
|
|||
|
$out['err'] = 0;
|
|||
|
$out['msg'] = 'файл загрузили';
|
|||
|
} else {
|
|||
|
$out['file'] = '';
|
|||
|
$out['path'] = $uploaddir;
|
|||
|
$out['err'] = 1;
|
|||
|
$out['err1'] = $_FILES[$name]["error"];
|
|||
|
$out['msg'] = 'файл не загрузили';
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return $out;
|
|||
|
}
|
|||
|
public function human_filesize($bytes) {
|
|||
|
$bytes = floatval($bytes);
|
|||
|
$arBytes = array(
|
|||
|
0 => array(
|
|||
|
"UNIT" => "Тб",
|
|||
|
"VALUE" => pow(1024, 4)
|
|||
|
),
|
|||
|
1 => array(
|
|||
|
"UNIT" => "Гб",
|
|||
|
"VALUE" => pow(1024, 3)
|
|||
|
),
|
|||
|
2 => array(
|
|||
|
"UNIT" => "Мб",
|
|||
|
"VALUE" => pow(1024, 2)
|
|||
|
),
|
|||
|
3 => array(
|
|||
|
"UNIT" => "Кб",
|
|||
|
"VALUE" => 1024
|
|||
|
),
|
|||
|
4 => array(
|
|||
|
"UNIT" => "б",
|
|||
|
"VALUE" => 1
|
|||
|
),
|
|||
|
);
|
|||
|
|
|||
|
foreach($arBytes as $arItem)
|
|||
|
{
|
|||
|
if($bytes >= $arItem["VALUE"])
|
|||
|
{
|
|||
|
$result = $bytes / $arItem["VALUE"];
|
|||
|
$result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"];
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
return $result;
|
|||
|
}
|
|||
|
public function translit($st)
|
|||
|
{
|
|||
|
$a = array_merge(array_combine(preg_split('//u', "абвгдеёзийклмнопрстуфхцьыэАБВГДЕЁЗИЙКЛМНОПРСТУФХЦЬЫЭabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"), preg_split('//u', "abvgdeeziyklmnoprstufhc'ieABVGDEEZIYKLMNOPRSTUFHC'IEabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_")), array("ж" => "zh", "ч" => "ch", "ш" => "sh", "щ" => "shch", "ъ" => "", "ю" => "yu", "я" => "ya", "Ж" => "Zh", "Ч" => "Ch", "Ш" => "Sh", "Щ" => "Shch", "Ъ" => "", "Ю" => "Yu", "Я" => "Ya"));
|
|||
|
$r = preg_split('//u', $st);
|
|||
|
$out = '';
|
|||
|
foreach ($r as $v) {
|
|||
|
if (isset($a[$v]))
|
|||
|
$out .= $a[$v];
|
|||
|
}
|
|||
|
return $out;
|
|||
|
}
|
|||
|
}
|