* * Licensed for free distribution under the GNU's General Public License ver. 2 * * You may copy, modify or redistribute this software as long as the above * * copyright and license notification remains unchanged. * * * * This is a very simple image gallery that allows people to upload files to * * the server and then view them online. it has a very simple display with some * * simple customization possibilities, mosty through a cascading style sheet. * * * * Source can be downloaded from: http://www.geek.co.il/galery/galeria.tar.gz * * * * Features: * * - Single file easy to install (two files with optional style sheet) * * - A bit customizable * * - Can be embedded in other pages easily * * - True small size thumbnails are generated automaticly with correct aspect * * ratio (no img width/height tricks) * * - Upload files directly from the gallery view. * * - Upload form can be auto-collapsed. * * - Images can open in a pop window. * * - Pop up image viewer with various resize and scale effect available * * - Paging support for unlimited number of images * * - Configurable charset * * * * Installation: * * Put in a directory where you want the images to be stored, and make sure the * * web server has write access to that directory: i.e. chmod 775 * * The images can be preloaded for the gallery by simply placing all the * * required images into the directory. note that this method does not allow you * * to set image titles, and the titles will be generated empty. * * * * Notes: * * This script was built for eonspace web server and assumes some things that * * will most likely be true only on that server. Assuming I didn't forget * * something, here are the assumptions in no particular order: * * * * - All web files are owned by a group the web server user is part of. if this * * is not true, then other measures have to be taken to make the gallery dir * * writeable by the PHP page. * * - the PHP ImageMagick extension is installed * * * * Good luck using it, and if you have any problems you can contact me using * * the above email address. * ********************************************************************************/ /** * Configuration section * Everything should be self explenatory, and what's not * has explenations attached :-) **/ /** * thumbnail view settings */ $max_images_per_page = 18; $max_images_per_line = 6; /** * Image titles can be shown above or below thumbnail */ $show_title_under_thumbnail = false; /** * max resolution for thumbnails. smaller images * will not be scaled, larger will be scaled to these * values using max aspect ratio. */ $thumbnail_max_x = 160; $thumbnail_max_y = 160; /** * Should full image view use a popup window ? */ $popup_image_window = true; /** * X and Y dimentions of popup window * If this is disabled then the browser will determine the * size automaticly which will probably be wrong. */ $popup_image_size = array( 600,600 ); /** * X and Y location of popup window * This is best left disabled, and hopefully the visitor's * window manager will be smart enough to place the window * correctly. */ //$popup_image_location = array( 10, 50 ); /** * Auto reise mode: */ $auto_resize = // "none"; // no auto resize at all // "fit small image"; // fit window to image if smaller then the window // "fit image"; // fit window to image up to screen size // "scale small image"; // scale a small image to the window size // "scale large image"; // scale a large image to the window size // "scale image"; // scale all images to the window size // "best fit"; // fit window to image upto screen size, resize larger images - default "fit and scale small"; // scale smaller images up to window size, do best fit for larger images /** * display a form to allow users to upload new images */ $allow_upload = false; /** * should auto-collapsing "magic" file upload form be used */ $collapsing_upload = true; /** * location relative to the root of the web site, where the images can be found * this is not the real path to the gallery but is used to create absolute URLs * that point to images and CSS file so that a browser can view them. * This entry must end with a / character. */ $base_url = detect_from_root(); // "/galery/"; /** * Should files that are suddenly missing from the thumbnail list * be silently ignored and removed from the list (assuming the * administrator has deleted them) ? * Other wise an error message will be generated and the script will fail. */ $ignore_missing_files = false; /** * Charset to use when not in embedded mode */ $charset = 'utf-8'; /** * When this value is set, the script will assume its being called * from other script that already setup the page. it will then not * print the HTML header and footer */ $embedded = false; /** * Cascading Style Sheet file to use, set to 'false' to disable CSS */ $style_sheet = 'style.css'; /** * Show "click this to view HTML source for embedding image and thumbnail" * button. */ $show_html_link = true; /** * -->> End of user configurable parameters - don't mess with * anything down here unless you know what you are doing. <<-- * * And I mean it !! **/ // variable decleration (yea, I know I don't have to. XSS countermeasures it is. $pager = 0; $request_string = ""; $gallery_directory = dirname($_SERVER['SCRIPT_FILENAME']); $PHP_SELF = $_SERVER['PHP_SELF']; // read the requested page foreach ($_REQUEST as $name => $value) { if ($name == 'page') $pager = $_REQUEST['page']; elseif ($name == 'display') $request_string .="&" . $name . "=" . $value; } // check for file upload if (is_array($_FILES['imagefile'])) { handle_files($_FILES['imagefile'],$_REQUEST['title']); header("Location: ?page=" . $pager . $request_string); die; } // Show the requested file if ($_REQUEST['showme']) show_file($_REQUEST['showme']); // honour open source policy and show the current script if ($_REQUEST['showsource']) { highlight_file(__FILE__); die; } // generate the header of the gallery if (!$embedded) gen_head(); // show thumbnail table for the requested page show_thumbs($pager); // show the upload form if ($allow_upload) gen_form(); gen_copyright(); // generate the footer if (!$embedded) gen_foot(); // nothing more to do here if ($embedded) return; exit(); /**************** implementation **************************/ /** * function detect_from_root * Used in base_url configuration to auto-detect the base_url * from the local path, given the component that corresponds to * the web site's root (usually 'public_html' which is assumed * if root_component isn't specified) */ function detect_from_root($root_component = 'public_html') { return dirname($_SERVER['PHP_SELF']) . "/"; /*if (strpos(__FILE__, $root_component) === false) return ""; return dirname(substr(__FILE__, strpos(__FILE__, $root_component) + strlen($root_component))) . "/";*/ } /** * function gen_head * Generates the header of the HTML page */ function gen_head() { global $base_url; global $style_sheet; global $charset; header("Content-Type: text/html" . ($charset?"; charset=$charset":"")); ?> Thumbnail gallery
May the source be with you
(c) 2003 Oded Arbel
0 and count($images)) array_shift($images); ?> = $max_images_per_page) { break; } // snap to next line - only if page wasn't done if ($line_counter >= $max_images_per_line) { $line_counter = 0; ?> $page_counter; $prev_page = $page > 0; if ($next_page or $prev_page) { ?>
S
[Upload]
Image file to upload:
Image title:

Note that only image files of type PNG, GIF and JPEG are acceptable
" ) ) { copy($file, $thumbfile); // fake it return $thumbfile; } if (!imagick_writeimage( $handle, $gallery_directory . "/" . $thumbfile ) ) { copy($file, $thumbfile); // fake it return $thumbfile; } return $thumbfile; } /** * function handle_files * read the uploaded files and get the hot stuff */ function handle_files($file, $title) { global $gallery_directory; $oldimages = get_images(); // compose a file name $target_name = sprintf("%04X",mt_rand(0,65535)) . "-" . basename($file['name']); $cur_path = $file['tmp_name']; if (!$cur_path or !file_exists($cur_path)) { print "Error! no file found!
\n\n"; print "
";
	    print_r($file);
	    print "
"; die; } // check the type of the file $mime = mime_content_type($cur_path); // make sure its a supported image type if ($mime != "image/png" and $mime != "image/jpeg" and $mime != "image/gif" and !stristr($target_name,"zip")) die("File is not a valid image file!"); // put the file in the gallery directory if (!copy($cur_path, $gallery_directory . "/" . $target_name)) die("Error moving uploaded file"); unlink($cur_path); // remove from the old path // store it in the list $oldimages[] = array($target_name, stripslashes($title)); save_images($oldimages); } /** * function show_file * create an HTML that embeds the image and forces it to the * required dimensions. * This still depends on the image file being accessible by the web server, * if this is an issue then I can fix it. */ function show_file($file) { global $gallery_directory; global $base_url; global $auto_resize; list($width, $height) = getimagesize($gallery_directory . "/" . $file); ?> <br /> <b>Warning</b>: Undefined variable $file in <b>/vhosts/coil/geek/public_html/galery/index.php</b> on line <b>686</b><br /> var maxX = screen.availWidth - 70; var maxY = screen.availHeight - 50; var targetWidth = (x > maxX ? maxX : x); var targetHeight = (y > maxY ? maxY : y); var noresize = false; // detect window size var windowX = 0; var windowY = 0; if (document.attachEvent) { // Internet Exploded windowX = document.body.clientWidth; windowY = document.body.clientHeight; } else { // Mozilla, Konqy windowX = window.innerWidth; windowY = window.innerHeight; } if (x < windowX && y < windowY) { targetWidth = windowX; targetHeight = windowY; noresize = true; } if (targetWidth < x || targetHeight < y) { // fix aspect ratio var xScale = targetWidth / x; var yScale = targetHeight / y; if (xScale > yScale) { // y was scaled more then X, rescale x targetWidth = x * yScale; // alert("Rescaling x by " + yScale); } else if (xScale < yScale) { // y was scaled less then X, rescale y targetHeight = y * xScale; //alert("Rescaling y by " + xScale); } } document.getElementById("theimage").width = targetWidth; document.getElementById("theimage").height = targetHeight; // move window so it won't overflow the screen on large images if (maxX < x || maxY < y) window.moveTo(0,0); if (!noresize) window.resizeTo(targetWidth+40,targetHeight+50); var maxX = screen.availWidth; var maxY = screen.availHeight; var maxfit = true; // detect window size var maxX; var maxY; var maxfit = false; if (document.attachEvent) { // Internet Exploded maxX = document.body.clientWidth; maxY = document.body.clientHeight; } else { // Mozilla, Konqy maxX = window.innerWidth; maxY = window.innerHeight; } if (x < maxX && y < maxY) { // fit window window.resizeTo(x+40,y+40); } else if (maxfit) { window.resizeTo(maxX,maxY); window.moveTo(0,0); } // detect window size var maxX; var maxY; var maxfit = false; if (document.attachEvent) { // Internet Exploded maxX = document.body.clientWidth; maxY = document.body.clientHeight; } else { // Mozilla, Konqy maxX = window.innerWidth; maxY = window.innerHeight; } if (x < maxX && y < maxY) { if (x > maxX && y > maxY) { if (1) { // fix aspect ratio var xScale = maxX / x; var yScale = maxY / y; if (xScale > yScale) { // y was scaled more then X, rescale x maxX = x * yScale; // alert("Rescaling x by " + yScale); } else if (xScale < yScale) { // y was scaled less then X, rescale y maxY = y * xScale; //alert("Rescaling y by " + xScale); } document.getElementById("theimage").width = maxX; document.getElementById("theimage").height = maxY; }