|
|
|
<?
/*****************************************
** **
** IMAGE BROWSER **
** **
** original code by shakib of **
** **
** http://www.mediumart.co.uk **
** **
*****************************************/
/* NOTES
this script is intended for use in a
directory empty of everything other
than image files (jpg and png, not
gif due to licensing restrictions)
this script will automatically generate
and save thumbnails of images that you
upload, and display these first off with
links to the full images
NOTE - image handling with php is not
the most efficient in the world - do not
try and parse more than 2 or 3 images at
a time.
USAGE:
1. upload this script to your images directory
2. upload a couple of sample images
3. create a sub-directory for the thumbnails
("thumbs" is the default)
4. browse to this script over http!
COPYRIGHT:
this script isn't copyright at all. you can
use it, modify it, sell it, claim it as your
own, whatever.
if you *want* to have a link back to us at
http://www.mediumart.co.uk that would be
great :)
*/
/* CONFIG */
// maximum width and height of thumbnails (will scale)
$maxw = 100;
$maxh = 75;
// directory to place thumbnail images
$thumbdir = "thumbs";
// number of columns in table
$cols = 4;
// number of rows in table
$rows = 4;
// default sorting method ["date","size","name"]
$df_sortby = "date";
// default ordering (ascending or descending) ["ASC","DESC"]
$df_ascdsc = "DESC";
/* INITIALISATION */
// useful shortcut
$url = $_SERVER["PHP_SELF"]."?";
// start point and ordering
$start = ( isset($_GET["start"]) ) ? $_GET["start"] : 0;
$sortby = ( isset($_GET["sortby"]) ) ? $_GET["sortby"] : $df_sortby;
$ascdsc = ( isset($_GET["ascdsc"]) ) ? $_GET["ascdsc"] : $df_ascdsc;
// allowed image types
// NOTE - to add image types (.gif for example)
// you must also alter the createThumb function
$sfxs = array(".jpg",".jpeg",".png");
// get the current directory path:
$curdir = dirname(stripslashes($_SERVER["PATH_TRANSLATED"]));
// get folder delimiter for this system:
$slash = ( strstr($curdir,"\\") ) ? "\\" : "/";
$thumbdir = $thumbdir;
/* READ DIRECTORY */
// create array to hold filenames and information
// $images[n][0] = name
// $images[n][1] = date
// $images[n][2] = size
$images = array();
@ $handle = opendir($curdir);
if ( !$handle ) {
error("could not open directory!");
exit;
}
while ( $file = readdir($handle) ) {
if ( isValid($file,$sfxs) ) {
$tmp = array();
$tmp[0] = $file;
$tmp[1] = filemtime($file);
$tmp[2] = filesize($file);
array_push($images,$tmp);
// do we need to create a thumbnail?
if ( !file_exists($thumbdir.$slash.$file) ) {
createThumb($file);
}
}
}
// now sort the dir:
usort($images,"sortme");
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>shakib's image browser</title>
<style>
body, td, input, select {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 0.8em;
background-color: #efefef;
color: #454545;
}
input, select {
border: 1px solid #666666;
}
a {
font-weight: bold;
color: #000000;
}
a:visited {
color: #787878;
}
a:hover {
color: #ff6600;
}
.img {
font-size: 0.7em;
border: 1px solid #666666;
text-align: center;
vertical-align: bottom;
padding: 5px 2px 5px 2px;
}
</style>
</head>
<body>
<p><small><a href="flash.php">flash version</a></small></p>
<h3 align="center">shakib's images</h3>
<?
/* CREATE TABLE */
$k = $start;
$n = count($images);
$ord = "&sortby=".$sortby."&ascdsc=".$ascdsc;
if ( $start > 0 ) {
$pn = $start - $rows*$cols;
$prev = '<a href="'.$url.$ord.'&start='.$pn.'">prev</a>';
} else {
$prev = "prev";
}
if ( $start + $rows*$cols < $n) {
$nn = $start + $rows*$cols;
$next = '<a href="'.$url.$ord.'&start='.$nn.'">next</a>';
} else {
$next = "next";
}
if ( $n-$k < $rows*$cols ) {
$rows = ceil(($n-$k)/$cols);
}
?>
<table border="0" align="center" width="<?=$cols*$maxw*1.4?>">
<tr>
<td colspan="<?=$cols?>" align="center">
<form name="f" action="<?=$_SERVER["PHP_SELF"]?>"
method="GET">
<input name="start" type="hidden" value="<?=$start?>">
sort by
<select name="sortby">
<option value="-1">-- sort by --</option>
<option value="date"<? if ($sortby=="date") echo "
SELECTED"?>>date</option>
<option value="size"<? if ($sortby=="size") echo "
SELECTED"?>>size</option>
<option value="name"<? if ($sortby=="name") echo "
SELECTED"?>>name</option>
</select>
<input name="ascdsc" value="ASC" type="radio"<? if
($ascdsc=="ASC") echo " CHECKED"?>>ascending
<input name="ascdsc" value="DESC" type="radio"<? if
($ascdsc=="DESC") echo " CHECKED"?>>descending
<input type="submit" value="re-sort">
</form>
</td>
</tr>
<tr>
<td colspan="<?=$cols?>"><hr></td>
</tr>
<tr>
<td colspan="<?=$cols?>">
<table width="100%">
<tr>
<td><?=$prev?></td>
<td align="right"><?=$next?></td>
</tr>
</table>
</td>
</tr>
<?
for ( $i=0; $i<$rows; $i++ ) {
?>
<tr>
<?
for ( $j=0; $j<$cols; $j++ ) {
?>
<td class="img" width="<?=round(100/$cols)?>%">
<?
if ( $k < $n ) {
?>
<a href=><?=$images[$k][0]?>" target="blank" alt="<?=$images
[$k][0]?>">
<?=$images[$k][0]?><br />
<img
src=><?=$thumbdir."/".$images[$k][0]?>"
border="0"
alt="<?=$images[$k][0]?>"
vspace="2"
style="filter:progid:DXImageTransform.Microsoft.Shadow
(color=#000000,direction=135,strength=5)">
</a><br />
<?=round($images[$k][2]/1024)?>Kb, <?=date("d-m-y",$images
[$k][1])?>
<?
} else {
?>
<?
}
?>
</td>
<?
$k++;
}
?>
</tr>
<?
}
?>
<tr>
<td colspan="<?=$cols?>"><hr></td>
</tr>
<tr>
<td colspan="<?=$cols?>" align="center">
the code that handles this archive is freely available, and
easy to plug into your own image
directory<br />
<a href="imgBrowser.zip" style="color:#000000">zipped php
source</a>
</td>
</tr>
</table>
</body>
</html>
<?
/*
USEFUL FUNCTIONS
*/
function isValid($f,$a) {
$t = getSuffix($f);
return ( in_array($t,$a) ) ? true : false;
}
function getSuffix($f) {
$n = strrpos($f,".");
return substr($f,$n,strlen($f)-$n);
}
function createThumb($f) {
// use max width config value
global $maxw, $maxh, $curdir, $thumbdir, $slash;
$type = getSuffix($f);
// png or jpeg?
// either way get image
if ($type==".png") {
$input = imagecreatefrompng($f);
} else {
$input = imagecreatefromjpeg($f);
}
if ( !$input ) {
error("not a valid image file :(");
return false;
}
// get size ( [0]=width, [1]=height )
$tmp = getimagesize($f);
if ( !$tmp ) {
error("Could not get input image size");
return false;
}
// get width of new thumbnail by taking
// the smaller value from max and tmp width
$w = ($tmp[0]>$maxw) ? $maxw : $tmp[0];
// scale height according to width
$h = $tmp[1] * ($maxw/$tmp[0]);
if ( $h>$maxh ) {
$h = $maxh;
$w = $tmp[0] * ($maxh/$tmp[1]);
}
// create output image
@ $output = imagecreate($w,$h);
if ( !$output ) {
error("could not create output image");
return false;
}
// copy big image over to thumbnail, and resize down
imagecopyresized( $output,$input, 0,0, 0,0, $w,$h, $tmp[0],$tmp[1] );
$newfile = $thumbdir.$slash.$f;
// do the outputting!
if ( $type == ".png" ) {
imagepng($output,$newfile);
} else {
imagejpeg($output,$newfile);
}
}
function sortme($a,$b) {
// setup
global $sortby, $ascdsc;
if ( $sortby == "name" ) {
$n = 0;
} elseif ( $sortby == "date" ) {
$n = 1;
} elseif ( $sortby == "size" ) {
$n = 2;
}
$m = ( $ascdsc == "ASC" ) ? 1 : -1;
if ( $a[$n] == $b[$n] ) return 0;
return ($a[$n] > $b[$n]) ? $m : -1*$m;
}
function error($str) {
echo '<div style="background-color:#ffffff;color:#660000;font-
weight:bold">'.$str.'</div>';
}
?> |
|
| File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection. Categories : Complete Programs, Content Management, Filesystem, PHP | | | This program implements hot link prevention in php. It is useful for webmasters who do not have access to the server at a level where they can control hot linking can still supply some type of hot link prevention for thier site by using php. Categories : PHP, Filesystem, Graphics, Content Management | | | QTO File Manager Categories : Filesystem, filePro, Complete Programs, PHP, Content Management | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality. Categories : PHP, GD image library, Graphics | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | Introduction to Language Files Categories : PHP, Filesystem, Beginner Guides | | | A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | php jump urls...the best way Categories : PHP, URLs, Filesystem | | | Simple way to replace a variable value in a .conf (.ini) file using a
webbrowser - the first stage of a complete universal configuration editor Categories : PHP, Regexps, Code Editors, Filesystem | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | |
|
|
|