function spit_phpthumb_image($filepath, $configarray = array()) { // set up class global $CFG, $PHPTHUMB_CONFIG; $phpThumb = new phpThumb(); // import default config if (!empty($PHPTHUMB_CONFIG)) { foreach ($PHPTHUMB_CONFIG as $key => $value) { $keyname = 'config_' . $key; $phpThumb->setParameter($keyname, $value); } } // import passed params if (!empty($configarray)) { foreach ($configarray as $key => $value) { $keyname = $key; $phpThumb->setParameter($keyname, $value); } } $phpThumb->setSourceFilename($filepath); if (!is_file($phpThumb->sourceFilename) && !phpthumb_functions::gd_version()) { if (!headers_sent()) { // base64-encoded error image in GIF format $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7'; header('Content-Type: image/gif'); echo base64_decode($ERROR_NOGD); } else { echo '*** ERROR: No PHP-GD support available ***'; } exit; } $phpThumb->SetCacheFilename(); if (!file_exists($phpThumb->cache_filename) && is_writable(dirname($phpThumb->cache_filename))) { // error_log("generating to cache: " . $phpThumb->cache_filename); $phpThumb->CleanUpCacheDirectory(); $phpThumb->GenerateThumbnail(); $phpThumb->RenderToFile($phpThumb->cache_filename); } if (is_file($phpThumb->cache_filename)) { // error_log("sending from cache: " . $phpThumb->cache_filename); if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) { $mimetype = phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]); } spitfile_with_mtime_check($phpThumb->cache_filename, $mimetype); } else { // error_log("phpthumb cache file doesn't exist: " . $phpThumb->cache_filename); $phpThumb->GenerateThumbnail(); $phpThumb->OutputThumbnail(); exit; } }
$phpthumb = true; $phpthumbconfig[$constraint2] = $size2; } // images most likely don't want compressing, and this will kill the Vary header if (function_exists('apache_setenv')) { // apparently @ isn't enough to make php ignore this failing @apache_setenv('no-gzip', '1'); } // user icons are public header("Pragma: public"); header("Cache-Control: public"); if (!$default && !$phpthumb && ($constraint1 == 'h' || $constraint1 == 'w') && (!$constraint2 || $constraint2 == 'h' || $constraint2 == 'w')) { // 100 pixels requested, redirect to attributeless icon url for cacheability fun header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently"); header("Location: " . $CFG->wwwroot . '_icon/user/' . $id); die; } if ($phpthumb) { // let phpthumb manipulate the image spit_phpthumb_image($filepath, $phpthumbconfig); } elseif ($default) { // no manipulation and default icon if ($id == -1) { header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently"); } header("Location: " . $CFG->wwwroot . '_icons/data/default.png'); die; } else { // output the image directly spitfile_with_mtime_check($filepath, $mimetype); }
<?php require_once dirname(dirname(__FILE__)) . '/../includes.php'; $userref = optional_param('userref'); $username = optional_param('username'); $type = optional_param('type'); $file = $CFG->dataroot . 'rss/' . $userref . '/' . $username . '/' . $type . '.xml'; error_log($file); if (!file_exists($file)) { @header('HTTP/1.0 404 Not Found'); exit; } header("Pragma: public"); header("Cache-Control: public"); require_once $CFG->dirroot . 'lib/filelib.php'; spitfile_with_mtime_check($file, "text/xml; charset=utf-8");
// Then output some appropriate headers and send the file data! // TODO: bug on ie, if using ssl force public cache control // using port, $_SERVER['HTTPS'] does not work always if ($file->access == 'PUBLIC' || isset($_SERVER['HTTPS']) || $_SERVER['SERVER_PORT'] == 443) { header("Pragma: public"); header("Cache-Control: public"); } else { // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header header("Cache-Control: private"); } require_once $CFG->dirroot . 'lib/filelib.php'; $mimetype = mimeinfo('type', $file->location); if ($mimetype == "application/octet-stream") { header('Content-Disposition: attachment'); } // disable mod_deflate/mod_gzip for already-compressed files, // partly because it's pointless, but mainly because some browsers // are thick. if (preg_match('#^(application.*zip|image/(png|jpeg|gif))$#', $mimetype)) { if (function_exists('apache_setenv')) { // apparently @ isn't enough to make php ignore this failing @apache_setenv('no-gzip', '1'); } } spitfile_with_mtime_check($CFG->dataroot . $file->location, $mimetype, $file->handler); exit; } } } }
// Icon script // Run includes require_once dirname(dirname(__FILE__)) . "/includes.php"; // Initialise functions for user details, icon management and profile management run("userdetails:init"); run("profile:init"); run("files:init"); // If an ID number for the file has been specified ... $id = optional_param('id', 0, PARAM_INT); if (!empty($id)) { // ... and the file exists ... if ($file = get_record('files', 'ident', $id)) { if (run("users:access_level_check", $file->access) == true) { require_once $CFG->dirroot . 'lib/filelib.php'; require_once $CFG->dirroot . 'lib/iconslib.php'; // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header header("Cache-Control: private"); // Then output some appropriate headers and send the file data! $mimetype = mimeinfo('type', $file->originalname); if ($mimetype == "image/jpeg" || $mimetype == "image/png") { // file is an image $phpthumbconfig['w'] = 90; spit_phpthumb_image($CFG->dataroot . $file->location, $phpthumbconfig); } else { // file is a file spitfile_with_mtime_check($CFG->dirroot . "_files/file.png", "image/png"); } } } }