$person_image_id = isset($_GET['person_image_id']) ? $_GET['person_image_id'] : null; $hint = isset($_GET['type']) ? $_GET['type'] : null; # Attempt to sanitize input a bit. At the very least, make attempts # to turn something into a filename bit work. if (isset($person_image_id)) { $person_image_id = basename($person_image_id); } if (isset($hint)) { $hint = basename($hint); } $showpic = 0; if ($person_id && $person_image_id) { $query = "\n\t\tselect person_id, person_image_id, image_blob, image_type,\n\t\t\tcoalesce(data_upd_date, data_ins_date) as last_updated\n\t\t from\tperson_image\n\t\t where\tperson_id = \$1\n\t\t and\tperson_image_id = \$2\n\t\t\tor (\$1 = \$2)\n\t"; $result = pg_query_params($query, array($person_id, $person_image_id)) or die("Bad Query"); if ($row = pg_fetch_array($result, null, PGSQL_ASSOC)) { if (!send_cached_image($dbconn, $row, $hint)) { $stdout = fopen("php://stdout", "w"); if (!copy_db_image($dbconn, $row, $stdout, 1)) { die("failed to display image #" . $row['image_blob']); } fclose($stdout); } else { $showpic = 1; } } pg_query($dbconn, "rollback"); pg_close($dbconn); } if (!$showpic && ($show_anything = 1)) { header("Content-type: image/png"); echo file_get_contents("images/600px-Smiley.svg.png");
@mkdir($candidatelocation, $CFG->directorypermissions, true); } // Make note we can not find this file. $cacheimage = "{$candidatelocation}/{$image}.error"; $fp = fopen($cacheimage, 'w'); fclose($fp); image_not_found(); } $cacheimage = cache_image($image, $imagefile, $candidatelocation); if (connection_aborted()) { die; } // Make sure nothing failed. clearstatcache(); if (file_exists($cacheimage)) { send_cached_image($cacheimage, $etag); } send_uncached_image($imagefile); //================================================================================= //=== utility functions == // we are not using filelib because we need to fine tune all header // parameters to get the best performance. function send_cached_image($imagepath, $etag) { global $CFG; require "{$CFG->dirroot}/lib/xsendfilelib.php"; $lifetime = 60 * 60 * 24 * 60; // 60 days only - the revision may get incremented quite often $pathinfo = pathinfo($imagepath); $imagename = $pathinfo['filename'] . '.' . $pathinfo['extension']; $mimetype = get_contenttype_from_ext($pathinfo['extension']);
$cacheimage = "$candidatelocation/$image.error"; $fp = fopen($cacheimage, 'w'); fclose($fp); } image_not_found(); } if ($rev > -1) { $pathinfo = pathinfo($imagefile); $cacheimage = "$candidatelocation/$image.".$pathinfo['extension']; if (!file_exists($cacheimage)) { check_dir_exists(dirname($cacheimage)); copy($imagefile, $cacheimage); } send_cached_image($cacheimage, $rev); } else { send_uncached_image($imagefile); } //================================================================================= //=== utility functions == // we are not using filelib because we need to fine tune all header // parameters to get the best performance. function send_cached_image($imagepath, $rev) { $lifetime = 60*60*24*30; // 30 days $pathinfo = pathinfo($imagepath); $imagename = $pathinfo['filename'].'.'.$pathinfo['extension'];