Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/image.php
<?php
/*
 *  Copyright 2008 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * This file is used to send internal image to browser.
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

/**
 */
require 'server_options.php';

/**
 * Including common entry file header
 */
require 'include/entry_common.php';

require_once 'include/common.php';


$ok = true;
$notFound = false;

if (isset($_GET['fileName'])) {
    $fileName = $_GET['fileName'];
    if (empty($fileName)) {
        $ok = false;
        $notFound = true;
    }
} else {
    $id = $_GET['id'];
    if (empty($id)) {
        $ok = false;
        $notFound = true;
    }
}

if ($ok) {
    configurateDataObject($dsn);
    if ($fileName) {
        $dao =& getDao('resource');
        $dao->findByFileName($fileName);
    } else {
        $dao =& staticGet('internal_image', $id);
    }
    if (empty($dao->id)) {
        $ok = false;
        $notFound = true;
    }
}


if (!$ok) {
    if ($notFound) {
        header("HTTP/1.0 404 Not Found");
    }
} else {
    if ($fileName) {
        $mimeType = detectMimeType($dao->file_name);
        switch ($mimeType) {
        case 'image/gif':
            $type = IMAGETYPE_GIF;
            break;
        case 'image/jpeg':
            $type = IMAGETYPE_JPEG;
            break;
        case 'image/png':
            $type = IMAGETYPE_PNG;
            break;
        default:
            $type = IMAGETYPE_JPEG;
            break;
        }
    } else {
        $type = $dao->type;
    }
    $data = $dao->data;
    $data = unescapeBlobFromSelect($data);

    $maxWidth = $_GET['maxWidth'];
    $maxHeight = $_GET['maxHeight'];
    if ($_GET['size'] == 'thumbnail') {
        $maxWidth = $thumbnailWidth;
        $maxHeight = $thumbnailHeight;
    } else if ($_GET['size'] == 'standard') {
        $maxWidth = $maxImageWidth;
        $maxHeight = $maxImageHeight;
    }

    if (isset($maxWidth) || isset($maxHeight)) {
        $resized = resizeImage($data, $dao->width, $dao->height, $type,
                $maxWidth, $maxHeight);
        $type = $resized['type'];
        $data = $resized['data'];
    }
    $typeStr = image_type_to_mime_type($type);
    header("Content-type: $typeStr");
    echo $data;
}
?>
Return current item: Blandware AtLeap Lite - CMS on PHP