示例#1
0
 function upload($index, $album_id = false, $album = '', $title = '', $descr = '')
 {
     if (!isset($_FILES[$index])) {
         return 'uploading error: file not found';
     }
     if (0 != $_FILES[$index]['error']) {
         return 'uploading error: #' . $_FILES[$index]['error'] . ' - ' . $this->error_code_decrypt($_FILES[$index]['error']);
     }
     //		if ('image/jpeg' != $_FILES[$index]['type']) {
     //			return 'uploading error: format not supported';
     //		}
     if (false === strpos($_FILES[$index]['type'], 'jpeg')) {
         return 'uploading error: format not supported';
     }
     $filename = get_uniq() . '.jpg';
     //		dbg($filename);
     // Save BIG picture
     if (move_uploaded_file($_FILES[$index]["tmp_name"], FLGR_PHOTOS_BIGS . '/' . $filename)) {
         // Processed
         // Открываем файл
         $rImg = imagecreatefromjpeg(FLGR_PHOTOS_BIGS . '/' . $filename);
         // Получаем размеры
         $nWidth = imagesx($rImg);
         $nHeight = imagesy($rImg);
         // Определяем, горизонтальный он или вертикальный
         $orientation = $this->get_orientation($nWidth, $nHeight);
         // normal
         if ($orientation == ORIENTATION_HORIZONTAL) {
             $nPixLimit = 604;
         } else {
             $nPixLimit = 480;
         }
         list($nX, $nY) = $this->get_proportional_scale($orientation, $nPixLimit, $nWidth, $nHeight);
         // Масштабируем
         $rNewImg = imagecreatetruecolor($nX, $nY);
         imagecopyresampled($rNewImg, $rImg, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
         // Сохраняем
         imagejpeg($rNewImg, FLGR_PHOTOS_BIGS . '/' . $filename);
         // thumbnail
         $nPixLimit = 100;
         list($nX, $nY) = $this->get_proportional_scale($orientation, $nPixLimit, $nWidth, $nHeight);
         // Масштабируем
         $rNewImg = imagecreatetruecolor($nX, $nY);
         imagecopyresampled($rNewImg, $rImg, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
         // Сохраняем
         imagejpeg($rNewImg, FLGR_PHOTOS_THUMBNAILS . '/' . $filename);
     }
     // Save to bd
     // get album id
     //		dbg($album_id);
     if ($album_id == false) {
         $sql = "SELECT `id` FROM `" . DB_PREFIX . DB_TBL_ALBUMS . "` WHERE \n\t\t\t\t`name` = '" . mysql_escape_string($album) . "'";
         $sql = mysql_query($sql);
         if (false == $sql) {
             my_die();
         }
         $album_id = mysql_fetch_assoc($sql);
         if (!empty($album_id)) {
             $album_id = current($album_id);
         }
     }
     if (!is_numeric($album_id)) {
         return 'upload error: album not found';
     }
     $sql = "INSERT INTO `" . DB_PREFIX . DB_TBL_PHOTOS . "` (`seg`, `off`, `filename`) VALUES (\n\t\t\t'album', \n\t\t\t'" . mysql_escape_string($album_id) . "', \n\t\t\t'{$filename}'\n\t\t\t)";
     $this->query($sql);
     // Return
     return true;
 }
示例#2
0
 function avatar_upload($index, $seg, $off)
 {
     //		dbg($_FILES);
     if (!isset($_FILES[$index])) {
         return 'uploading error: file not found';
     }
     if (0 != $_FILES[$index]['error']) {
         return 'uploading error: #' . $_FILES[$index]['error'] . ' - ' . $this->error_code_decrypt($_FILES[$index]['error']);
     }
     if (false === strpos($_FILES[$index]['type'], 'jpeg')) {
         return 'uploading error: format not supported';
     }
     $filename = get_uniq(21) . '.jpg';
     //		dbg($filename);
     // Save BIG picture
     move_uploaded_file($_FILES[$index]["tmp_name"], FLGR_AVATARS_BIGS . '/' . $filename);
     // Processed
     // Открываем файл
     $rImg = imagecreatefromjpeg(FLGR_AVATARS_BIGS . '/' . $filename);
     // Получаем размеры
     $nWidth = imagesx($rImg);
     $nHeight = imagesy($rImg);
     //			dbg($nWidth, $nHeight);
     // bigs
     list($nX, $nY) = $this->get_proportional_scale(ORIENTATION_HORIZONTAL, $this->nAvatarBig, $nWidth, $nHeight);
     //			dbg($nX, $nY);
     // Масштабируем
     $rNewImg = imagecreatetruecolor($nX, $nY);
     imagecopyresampled($rNewImg, $rImg, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
     // Обрезаем если надо
     if ($nY > 300) {
         $rCrop = imagecreatetruecolor($nWidth, 300);
         imagecopyresized($rCrop, $rNewImg, 0, 0, 0, 0, $nWidth, 300, $nWidth, 300);
         $rNewImg = $rCrop;
         $nY = 300;
     }
     // Сохраняем
     imagejpeg($rNewImg, FLGR_AVATARS_BIGS . '/' . $filename);
     // normals
     $nWidth = $nX;
     $nHeight = $nY;
     list($nX, $nY) = $this->get_proportional_scale(ORIENTATION_HORIZONTAL, $this->nAvatarNormal, $nWidth, $nHeight);
     // Масштабируем
     $rNormals = imagecreatetruecolor($nX, $nY);
     imagecopyresampled($rNormals, $rNewImg, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
     // Сохраняем
     imagejpeg($rNormals, FLGR_AVATARS_NORMALS . '/' . $filename);
     // thumbnail
     $nWidth = $nX;
     $nHeight = $nY;
     list($nX, $nY) = $this->get_proportional_scale(ORIENTATION_HORIZONTAL, $this->nAvatarThumbnail, $nWidth, $nHeight);
     // Масштабируем
     $rThumbNail = imagecreatetruecolor($nX, $nY);
     imagecopyresampled($rThumbNail, $rNormals, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
     // Сохраняем
     imagejpeg($rThumbNail, FLGR_AVATARS_THUMBNAILS . '/' . $filename);
     // Save to bd
     global $Db;
     $sql = $Db->sqlGetInsert(DB_PREFIX . DB_TBL_AVATARS, array('seg' => $seg, 'off' => $off, 'filename' => $filename));
     //		dbg($sql);
     $Db->query($sql);
     $avatar_id = mysql_insert_id();
     // Return
     return true;
 }
示例#3
0
 function upload($index, $album, $album_id = false, $title = '', $descr = '')
 {
     if (!isset($_FILES[$index])) {
         return 'uploading error: file not found';
     }
     if (0 != $_FILES[$index]['error']) {
         return 'uploading error: #' . $_FILES[$index]['error'] . ' - ' . $this->error_code_decrypt($_FILES[$index]['error']);
     }
     if ('image/jpeg' != $_FILES[$index]['type']) {
         return 'uploading error: format not supported';
     }
     $filename = get_uniq() . '.jpg';
     // Save BIG picture
     move_uploaded_file($_FILES[$index]["tmp_name"], $this->sBigDir . '/' . $filename);
     // Processed
     // Открываем файл
     $rImg = imagecreatefromjpeg($this->sBigDir . '/' . $filename);
     // Получаем размеры
     $nWidth = imagesx($rImg);
     $nHeight = imagesy($rImg);
     // Определяем, горизонтальный он или вертикальный
     $orientation = $this->get_orientation($nWidth, $nHeight);
     // normal
     list($nX, $nY) = $this->get_proportional_scale($orientation, $this->nNormal, $nWidth, $nHeight);
     // Масштабируем
     $rNewImg = imagecreatetruecolor($nX, $nY);
     imagecopyresampled($rNewImg, $rImg, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
     // Сохраняем
     imagejpeg($rNewImg, $this->sNormalDir . '/' . $filename);
     // thumbnail
     list($nX, $nY) = $this->get_proportional_scale($orientation, $this->nThumbnail, $nWidth, $nHeight);
     // Масштабируем
     $rNewImg = imagecreatetruecolor($nX, $nY);
     imagecopyresampled($rNewImg, $rImg, 0, 0, 0, 0, $nX, $nY, $nWidth, $nHeight);
     // Добавляем контур
     $rStroke = imagecreatetruecolor($nX + 2, $nY + 2);
     imagecopy($rStroke, $rNewImg, 1, 1, 0, 0, $nX + 2, $nY + 2);
     imagerectangle($rStroke, 0, 0, $nX + 2 - 1, $nY + 2 - 1, 0x7f7f7f);
     // Добавляем поля
     $rThumbNail = imagecreatetruecolor($this->nBrutto, $this->nBrutto);
     imagefill($rThumbNail, 0, 0, 0xffffff);
     imagecopy($rThumbNail, $rStroke, ($this->nBrutto - $nX + 2) / 2 - 1, ($this->nBrutto - $nY + 2) / 2 - 1, 0, 0, $nX + 2, $nY + 2);
     // Добавляем второй контур
     imagerectangle($rThumbNail, 0, 0, $this->nBrutto - 1, $this->nBrutto - 1, 0x7f7f7f);
     // Сохраняем
     imagejpeg($rThumbNail, $this->sThumbnailDir . '/' . $filename);
     // Save to bd
     // get album id
     if ($album_id == false) {
         $sql = "SELECT `id` FROM `" . DB_PREFIX . DB_TBL_ALBUMS . "` WHERE \n\t\t\t\t`name` = '" . mysql_escape_string($album) . "'";
         $sql = mysql_query($sql);
         if (false == $sql) {
             my_die();
         }
         $album_id = mysql_fetch_assoc($sql);
         if (!empty($album_id)) {
             $album_id = current($album_id);
         }
     }
     if (!is_numeric($album_id)) {
         return 'upload error: album not found';
     }
     $sql = "INSERT INTO `" . DB_PREFIX . DB_TBL_IMGS . "` (`album_id`, `name`, `file`, `title`, `descr`) VALUES (\n\t\t\t'" . mysql_escape_string($album_id) . "', \n\t\t\t'" . mysql_escape_string($_FILES[$index]['name']) . "', \n\t\t\t'{$filename}',\n\t\t\t'" . mysql_escape_string($title) . "',\n\t\t\t'" . mysql_escape_string($descr) . "'\n\t\t\t)";
     $sql = mysql_query($sql);
     if (false == $sql) {
         my_die();
     }
     // Return
     return true;
 }