function getThumb() { global $db, $prefix, $iConfig, $moduleName; $pictureId = intval($_GET['pictureid']); $thumbsPath = $iConfig['thumbs_path']; $uploadPath = $iConfig['upload_path']; $thumbsFormat = strtolower($iConfig['thumbs_format']); $thumbsRealPath = iPath($thumbsPath); if ($pictureId) { $picture = $db->sql_fetchrow($db->sql_query('SELECT * FROM ' . $prefix . '_igallery_pictures WHERE picture_id=' . $pictureId . ' LIMIT 0,1')); $filename = $picture['picture_file']; $pictureType = $picture['picture_type']; $albumId = intval($picture['album_id']); $album = $db->sql_fetchrow($db->sql_query('SELECT album_title, album_folder FROM ' . $prefix . '_igallery_albums WHERE album_id=\'' . $albumId . '\' LIMIT 0,1')); $folderName = $album['album_folder']; $info = pathinfo($filename); $rawFilename = str_replace($info['extension'], '', $filename); if ($pictureType) { $thumb = iPath($uploadPath . 'thumbs/' . $rawFilename . $thumbsFormat); if (file_exists($thumb)) { $thumbPath = $thumb; } else { createThumb($moduleName, '', $filename, $type = 1); $thumbPath = NUKE_BASE_DIR . 'modules/' . $moduleName . '/images/no_image.png'; } } else { $thumb = iPath($thumbsPath . $folderName . '/' . $rawFilename . $thumbsFormat); if (!file_exists($thumbsRealPath . $folderName)) { @mkdir($thumbsRealPath . $folderName); } if (file_exists($thumb)) { $thumbPath = $thumb; } else { createThumb($moduleName, $folderName, $filename); $thumbPath = NUKE_BASE_DIR . 'modules/' . $moduleName . '/images/no_image.png'; } } } if (!isset($thumbPath) || empty($thumbPath)) { $thumbPath = NUKE_BASE_DIR . 'modules/' . $moduleName . '/images/no_image.png'; } if (file_exists($thumbPath) && is_readable($thumbPath)) { $info = getimagesize($thumbPath); $offset = 3600 * 24 * 60; // Set offset to keep in cache for 2 months (thumbs would not really change that much) header('Cache-Control: max-age=' . $offset . ', must-revalidate'); header('Content-type: ' . $info['mime']); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $offset) . ' GMT'); // check if the browser is sending a $_SERVER['HTTP_IF_MODIFIED_SINCE'] global variable if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { // if the browser has a cached version of this image, send 304 header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304); exit; } header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($thumbPath)) . ' GMT'); ob_start(); readfile($thumbPath); //ob_end_flush(); $outputImage = ob_get_contents(); //header('Content-length: '.ob_get_length()); //This was causing a loop reloading the picture 'til browser just give up (Google Chrome) ob_end_clean(); echo $outputImage; } exit; }
function galPreviewUploaded() { global $db, $prefix, $iConfig, $moduleName; $uploadPath = $iConfig['upload_path']; $filename = $_GET['file']; $img = iPath($uploadPath . $filename); if (file_exists($img)) { $imgPath = $img; } else { $imgPath = NUKE_BASE_DIR . 'modules/' . $moduleName . '/images/no_image.png'; } $info = getimagesize($imgPath); header('Content-type: ' . $info['mime']); readfile($imgPath); exit; }