/** загрузка(сохранение/обновление) аватара * @param integer ID записи * @param boolean удалять предыдущий аватар * @return имя файла успешно загруженной аватары | false */ function update($nRecordID, $bDeletePrevious = false, $bDoUpdateQuery = false) { global $oDb; if ($nRecordID && !empty($_FILES) && $_FILES[$this->input]['error'] == UPLOAD_ERR_OK) { $oUpload = new Upload($this->input, false); $aImageSize = getimagesize($_FILES[$this->input]['tmp_name']); if ($oUpload->isSuccessfull() && $aImageSize !== FALSE && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { if ($bDeletePrevious) { $this->delete($nRecordID, false); } $sExtension = func::image_type_to_extension($aImageSize[2], false); $sFilename = Func::generateRandomName($this->filenameLetters, true, true) . '.' . $sExtension; //проверяем размер файла if (!$oUpload->checkSize($this->maxsize)) { return false; } //создаем thumbnail $oThumb = new thumbnail($_FILES[$this->input]['tmp_name']); $oThumb->jpeg_quality(85); $oThumb->crop_proportionaly(1, 1, 'middle', 'center'); $oThumb->createTumbnail_if_more_then($this->path . $nRecordID . '_' . $sFilename, $this->width, $this->height, true); @unlink($_FILES[$this->input]['tmp_name']); if ($bDoUpdateQuery) { $oDb->execute("UPDATE {$this->table} \n SET {$this->fieldAvatar} =" . $oDb->str2sql($sFilename) . "\n WHERE {$this->fieldID} = {$nRecordID} "); } return $sFilename; } } return false; }
/** загрузка(сохранение/обновление) скриншота * @param integer ID записи * @param boolean удалять предыдущий скриншот * @return имя файла успешно загруженного скриншота | false */ function update($nRecordID, $bDeletePrevious = false, $bDoUpdateQuery = false) { global $oDb; if ($nRecordID && !empty($_FILES) && $_FILES[$this->input]['error'] == UPLOAD_ERR_OK) { $oUpload = new Upload($this->input, false); $aImageSize = getimagesize($_FILES[$this->input]['tmp_name']); if ($oUpload->isSuccessfull() && $aImageSize !== FALSE && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { if ($bDeletePrevious) { $this->delete($nRecordID, false); } $sExtension = func::image_type_to_extension($aImageSize[2], false); $sFilename = Func::generateRandomName($this->filenameLetters, true, true) . '.' . $sExtension; //проверяем размер файла if (!$oUpload->checkSize($this->maxsize)) { return false; } //создаем thumbnail $oThumb = new thumbnail($_FILES[$this->input]['tmp_name']); $oThumb->jpeg_quality(85); $bFileMoved = false; foreach ($this->sizes as $s) { if (!empty($s['original'])) { $oUpload->save($this->path, $nRecordID . '_' . $s['p'] . $sFilename, false, false); $bFileMoved = true; break; } $oThumb->createTumbnail_if_more_then($this->path . $nRecordID . '_' . $s['p'] . $sFilename, $s['w'], $s['h'], isset($s['autofit']) ? $s['autofit'] : true); } if (!$bFileMoved) { @unlink($_FILES[$this->input]['tmp_name']); } if ($bDoUpdateQuery) { $oDb->execute("UPDATE {$this->table} \n SET {$this->fieldPreview} =" . $oDb->str2sql($sFilename) . "\n WHERE {$this->fieldID} = {$nRecordID}"); } return $sFilename; } } return false; }
/** * Загрузка файлов изображений, при помощи input=file * @param integer ID записи * @param integer кол-во букв в сгенерированном имени файла * @return string имена загруженных файлов @example: '1.jpg,2.jpg' (CSV) */ function uploadImages($ID, $nGenerateLettersCount = 5) { $aFilenames = array(); if (func::isPostMethod()) { $ID = intval($ID); if (empty($nGenerateLettersCount)) { $nGenerateLettersCount = 5; } foreach ($_FILES as $sInputName => $aFile) { if ($aFile['name'] != '') { $pUpload = new Upload($sInputName); $aImageSize = getimagesize($pUpload->getFilenameUploaded()); if ($aImageSize !== FALSE && $pUpload->isSuccessfull() && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { $sExtension = func::image_type_to_extension($aImageSize[2], false); $sFilename = Func::generateRandomName($nGenerateLettersCount, false, true); $sFilenameFull = "{$sFilename}.{$sExtension}"; if ($this->saveImageFile($ID, $sFilenameFull, $pUpload, array('name' => $sFilename, 'ext' => $sExtension))) { $aFilenames[] = $sFilenameFull; } } } } } if (count($aFilenames) > 0) { $sFilenames = implode(',', $aFilenames); } return isset($sFilenames) ? $sFilenames : ''; }
function save($save = "", $bMakeWatermark = false, $nRoundCornersRadius = false) { if ($this->bSaveAsOriginal) { $res = @copy($this->sSourcePath2file, $save); if (!$res) { echo 'cann`t writre to ' . $save; exit; } } if (extension_loaded('gd') || extension_loaded('gd2')) { if (!function_exists('imagecreatetruecolor')) { str2log(__CLASS__ . '::' . __FUNCTION__ . ' - cant`t find ImageCreateTrueColor()', 'error.log'); return false; } if (!function_exists('imagecopyresampled')) { str2log(__CLASS__ . '::' . __FUNCTION__ . ' - cant`t find ImageCopyResampled()', 'error.log'); return false; } //save thumb if (empty($save)) { $save = mb_strtolower('./thumb' . func::image_type_to_extension($this->img['format'], true)); } /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"], $this->img["tinggi_thumb"]); // задаем чересстрочный режим //if ($this->bProgressive) ImageInterlace($this->img["des"], 1); if ($this->img['format'] == IMAGETYPE_PNG || $this->img['format'] == IMAGETYPE_GIF) { @ImageAlphaBlending($this->img["des"], false); @ImageSaveAlpha($this->img["des"], true); } ImageCopyResampled($this->img["des"], $this->img["src"], 0, 0, $this->img['src_x'], $this->img['src_y'], $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img['lebar'], $this->img['tinggi']); if ($bMakeWatermark) { $this->make_watermark('des', $this->img["lebar_thumb"], $this->img["tinggi_thumb"]); } $nImageFormat = $this->img['format']; if (isset($nRoundCornersRadius) && $nRoundCornersRadius !== false && $nRoundCornersRadius > 0) { $this->make_roundcorners('des', $nRoundCornersRadius); $nImageFormat = IMAGETYPE_PNG; } //сохраняем картинку switch ($nImageFormat) { case IMAGETYPE_GIF: imageGIF($this->img['des'], $save); break; case IMAGETYPE_JPEG: imageJPEG($this->img['des'], $save, $this->img['quality']); break; case IMAGETYPE_PNG: imagePNG($this->img['des'], $save); break; case IMAGETYPE_WBMP: imageWBMP($this->img['des'], $save); break; } ImageDestroy($this->img['des']); } else { $res = system('convert ' . $this->img['src'] . ' ' . '-resize "' . $this->img["lebar_thumb"] . 'x' . $this->img["tinggi_thumb"] . '" ' . $save . ' > /dev/null 2>/opt/hosting/www.alof.com/htdocs/log.txt', $retval); //debug('convert '.'-resize '.((int)$this->img["lebar_thumb"]).'x'.((int)$this->img["tinggi_thumb"]).' '.$this->img['src'].' '.$save); $res = system('convert -version'); if (!$res) { debug('Sorry, imageMagic - not defined!. GD library not defined!. Please Contact to administrator.'); exit; } } return true; }