setConfig($oConfig); $sShareUrl = null; $iResult = $oSharer->doShare($sShareUrl); if ($iResult == 1) { print $sBaseUrl . $sShareUrl; } else { print $sBaseUrl . '?ec=' . $iResult; } } else { error_log('Sign is incorrect => iAuid:' . $iAuid . ' sSign:' . $sSign . ' sScriptUri:' . $sScriptUri); print $sBaseUrl . '?ec=1001'; //подпись не совпадает } } else { error_log('Some parameters are not set => iAuid:' . $iAuid . ' sSign:' . $sSign . ' Image:' . ($Image ? '+' : '-')); print $sBaseUrl . '?ec=1000'; //пропущены обязательные параметры }
auid = $auid; $this->fileInfo = $fileInfo; $this->previewInfo = $previewInfo; $this->shareType = $shareType; $this->sign = $sign; } /** * @param $sFolder */ private function createFolder($sFolder) { if (!file_exists($sFolder)) { mkdir($sFolder, 0777); } } /** * @return null|string */ private function createUserFolder() { if ($this->auid) { $shareFolder = dirname(__FILE__) . '/../../' . $this->oConfig->shareFolderName; $this->createFolder($shareFolder); $shareFolder10000 = $shareFolder . (intval($this->auid/10000)) . '/'; $this->createFolder($shareFolder10000); $shareFolder1000 = $shareFolder10000 . (intval($this->auid/1000)) . '/'; $this->createFolder($shareFolder1000); $shareFolder100 = $shareFolder1000 . (intval($this->auid/100)) . '/'; $this->createFolder($shareFolder100); $shareFolder1 = $shareFolder100 . (intval($this->auid)) . '/'; $this->createFolder($shareFolder1); return $shareFolder1; } return null; } /** * @return string */ public function getUserFolder() { return $this->oConfig->shareFolderName . intval($this->auid/10000) . '/' . intval($this->auid/1000) . '/' . intval($this->auid/100) . '/' . intval($this->auid) . '/'; } /** * @param $oConfig */ public function setConfig($oConfig) { $this->oConfig = $oConfig; $this->dbInfo = array( 'mysqlHost' => $this->oConfig->host, 'mysqlUser' => $this->oConfig->user, 'mysqlPassword' => $this->oConfig->password, 'mysqlDB' => $this->oConfig->db, ); } /** * @param $auid */ public function setAuid($auid) { $this->auid = $auid; } /** * @param $sResult * @return int */ public function doShare(& $sResult) { $sUserFolder = $this->createUserFolder(); if (!$sUserFolder) return 1003; //ошибка при загрузке файла на сервер $time = time(); // Заливаем основную картинку $imageInfo = getimagesize($this->fileInfo['tmp_name']); if (empty($imageInfo[0]) || empty($imageInfo[1])) return 1002; //неверный тип файла if (!in_array($imageInfo['mime'], $this->allowedMime)) return 1002; //неверный тип файла $aExt = explode('/', $imageInfo['mime']); $fileName = $time . '.' . $aExt[1]; $sDest = $sUserFolder . $fileName; move_uploaded_file($this->fileInfo['tmp_name'], $sDest); // Заливаем превью (если есть что) $previewFileName = ''; if ($this->previewInfo) { $imageInfo = getimagesize($this->previewInfo['tmp_name']); if (empty($imageInfo[0]) || empty($imageInfo[1])) return 1002; //неверный тип файла if (!in_array($imageInfo['mime'], $this->allowedMime)) return 1002; //неверный тип файла $aExt = explode('/', $imageInfo['mime']); $previewFileName = $time . '-thumb.' . $aExt[1]; $sDest = $sUserFolder . $previewFileName; move_uploaded_file($this->previewInfo['tmp_name'], $sDest); } // Сохраняем, формируем ответ, если ОК $iResult = $this->save($fileName, $previewFileName); if (!$iResult) return 1004; $sResult = '?share='.$iResult; return 1; } /** * @param $fileName * @param string $previewFileName * @return mixed */ public function save($fileName, $previewFileName = '') { $oSQL = mysqlConnect::getInstance($this->dbInfo); $oSQL->query('INSERT INTO tbl_share_info (auid, filename, preview_filename, sharedate) VALUES (' . intval($this->auid) . ', "' . $fileName . '", "' . $previewFileName . '", NOW())'); return $oSQL->insert_id; } /** * @param $id * @return mixed */ public function get($id) { $oSQL = mysqlConnect::getInstance($this->dbInfo); $oResult = $oSQL->query('SELECT * FROM tbl_share_info WHERE id=' . intval($id)); return $oResult->fetch_array(); } /** * @param $id * @return int */ public function getPrev($id) { $oSQL = mysqlConnect::getInstance($this->dbInfo); $oResult = $oSQL->query('SELECT MAX(id) as prev FROM tbl_share_info WHERE idfetch_array(); return intval($aRow['prev']); } /** * @param $id * @return int */ public function getNext($id) { $oSQL = mysqlConnect::getInstance($this->dbInfo); $oResult = $oSQL->query('SELECT MIN(id) as next FROM tbl_share_info WHERE id>' . intval($id)); $aRow = $oResult->fetch_array(); return intval($aRow['next']); } /** * @param $auid * @return mixed */ public function checkUserScreens($auid) { $oSQL = mysqlConnect::getInstance($this->dbInfo); $oResult = $oSQL->query('SELECT COUNT(*) AS iCnt FROM tbl_share_info WHERE auid=' . intval($auid)); $aRow = $oResult->fetch_assoc(); return $aRow['iCnt']; } /** * @param $auid * @return array */ public function getUserScreens($auid) { $oSQL = mysqlConnect::getInstance($this->dbInfo); $oResult = $oSQL->query('SELECT * FROM tbl_share_info WHERE auid=' . intval($auid) . ' ORDER BY sharedate DESC'); $aResult = array(); while ($aRow = $oResult->fetch_assoc()) { $aResult[] = $aRow; } return $aResult; } }
options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); if (!self::$oDbInstance[$sKey]->real_connect( $connectionData['mysqlHost'], $connectionData['mysqlUser'], $connectionData['mysqlPassword'], $connectionData['mysqlDB'] )) { self::$oDbInstance[$sKey] = null; } else { self::$oDbInstance[$sKey]->set_charset('utf8'); } } return self::$oDbInstance[$sKey]; } public function __destruct() { /*if (self::$oDbInstance) { self::$oDbInstance->close(); self::$oDbInstance = null; }*/ } }