%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 13.59.75.169 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/webdebug.antirutin/lib/ |
Upload File : |
<? /** * Class to work with file uploader */ namespace WD\Antirutin; use \WD\Antirutin\Helper; class Uploader { /** * Upload file */ public static function uploadFile($strBase64Data, $strName=null, $strMimeType=null){ $mResult = null; # if(preg_match('#^data:([a-z0-9-.]+/[a-z0-9-.]+);base64,#i', $strBase64Data, $arMatch)){ if(is_null($strMimeType) || !strlen($strMimeType)){ $strMimeType = $arMatch[1]; } $strBase64Data = substr($strBase64Data, strlen($arMatch[0])); } # $strDir = static::getTmpDir().randString(16, 'abcdefghijklnmopqrstuvwxyz'); if(!is_dir(Helper::root().$strDir)){ mkdir(Helper::root().$strDir, BX_DIR_PERMISSIONS, true); } $strFile = strlen($strName) ? $strName : md5(randString(32)).static::getTypeExtension($strMimeType, true); $strFilename = $strDir.'/'.$strFile; # if($intSize = file_put_contents(Helper::root().$strFilename, base64_decode($strBase64Data, true))){ $mResult = [ 'Name' => $strFilename, 'Size' => $intSize, 'Type' => $strMimeType, ]; } return $mResult; } /** * Get upload temporary directory */ public static function getTmpDir(){ $strDir = sprintf('/%s/%s/tmp/', Helper::getOption('upload_dir', 'upload', 'main'), WDA_MODULE); if(!is_dir(Helper::root().$strDir)){ mkdir(Helper::root().$strDir, BX_DIR_PERMISSIONS, true); } return $strDir; } /** * Get extension by type */ public static function getTypeExtension($strType, $bDot=false){ $arTypes = [ 'image/jpg' => 'jpg', 'image/jpeg' => 'jpeg', 'image/png' => 'png', 'image/gif' => 'gif', 'image/bmp' => 'bmp', ]; return isset($arTypes[$strType]) ? ($bDot ? '.' : '').$arTypes[$strType] : null; } /** * Agent method for remove old files */ public static function agentRemoveTmpUploads(){ $strTmpDir = Helper::root().static::getTmpDir(); $arDirs = Helper::scandir($strTmpDir, [ 'FILES' => false, 'DIRS' => true, 'RECURSIVELY' => false, ]); $intStoragePeriod = intVal(Helper::getOption('upload_storage_period')); $intTime = time(); if($intStoragePeriod > 0){ foreach($arDirs as $intDirKey => $strDir){ $arFiles = Helper::scandir($strDir, [ 'FILES' => true, 'DIRS' => false, 'RECURSIVELY' => false, ]); foreach($arFiles as $intFileKey => $strFile){ if($intTime - filemtime($strFile) > $intStoragePeriod){ @unlink($strFile); if(!is_file($strFile)){ unset($arFiles[$intFileKey]); } } } if(empty($arFiles)){ @rmdir($strDir); } } } return sprintf('%s();', __METHOD__); } } ?>