/    Sign up×
Community /Pin to ProfileBookmark

Preview Folder Content via thumbnails

Is there a way “view as thumbnails” option… for the web forlder content (images only, or any content)? Kind of as if you were “exploring” a folder?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@BeachSideMay 17.2005 — you can use an .htaccess file to do this if I am not mistaken
Copy linkTweet thisAlerts:
@bokehMay 17.2005 — you can use an .htaccess file to do this if I am not mistaken[/QUOTE]Really? How?
Copy linkTweet thisAlerts:
@BeachSideMay 17.2005 — Really? How?[/QUOTE]


You can't I was thinking of something else sorry. I thought they were talking about the little image icons instead of the standard list list format.

:o
Copy linkTweet thisAlerts:
@bokehMay 17.2005 — Ok! Seeing as nobody else has come up with an answer I thought I'd give it a go. Put the following code in a file named thumbnail.php. Put the file in the directory containing the images and call it with the browser. If you want to put it in a different directory you will have to play with the various paths. It works as is though from the image directory. Don't forget, name it thumbnail.php. Ok?
[code=php]
<?php
if(isset($_GET['src'])){

// The file
$filename = $_GET['src'];

// Set a maximum height and width
$width = 70;
$height = 70;

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
imagejpeg($image_p, null, 100);

}else{

echo <<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="resource-type" content="document" />
<meta name="description" content="Thumbnails." />
<meta name="keywords" content="Thumbnails" />
<meta name="distribution" content="global" />

<style type="text/css">
ul#gallery {
margin:0 auto;
padding:0;
list-style-type:none;
width:90%;
}
ul#gallery li {
float: left;
margin:20px;
height:125px;
}
ul#gallery li img {
border: 0;
}
ul#gallery li p {
text-align: center;
margin:5px 0;
}
ul#gallery li p a {
text-decoration: none;
}
</style>

<title>Thumbnails</title>
</head>

<body>

<ul id="gallery">

END;

$dir = opendir($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']));

while (false !== ($file = readdir($dir))) {
if (eregi('.jpg{1}$', $file)){
print ('<li><a href="' . $file . '"><img src="thumbnail.php?src=' . $file . '"></a><p><a href="' . $file . '">' . str_replace('.jpg', '', $file) . '</a></p></li>'. "n");
}
}
closedir($dir);

echo <<<END
</ul>

</body>
</html>
END;

}
?>
[/code]
Copy linkTweet thisAlerts:
@SheldonMay 18.2005 — you could use his script provided by [B]Jona{/B] as an download somewhere in the php forum with images and all.



[code=php]
<?php
clearstatcache();
/***
Dynamic Directory Listing Script by Jona
***/
if(isset($_GET["phpinfo"])){
phpinfo();
exit;
}
if(isset($_GET["extns"])){
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css"><!--
body {
background-color: #CCC;
color: black;
font-family: arial, sans-serif;
font-size: small;
}
h1 {background-color: #AAA;
padding: 10px;
border: solid 1px black;
margin-bottom: 0px;
font-size: medium;
font-weight: normal;}
ul {margin-top: 0px;
padding-top: 5px;
padding-bottom: 5px;
list-style:square;
background-color: #999;
border:solid 1px black;}
--></style>
<title>Installed PHP Extensions</title>
</head>
<body>
<h1>Below is a list of the installed PHP extensions on this server.</h1>
<ul><?php
$extns = get_loaded_extensions();
for($j=0; $j<count($extns); $j++)
{echo("<li>". ucwords($extns[$j]) ."</li>");}
?></ul>
</body></html><?
exit;
}

// time begin
$sTime = time();

// directory name
$dir = getcwd();

// icons to use
$icons = array("htm" => "html.gif", "html" => "html.gif", "php" => "php.gif", "." => "dir.gif", ".." => "dir.gif", "gif" => "gif.gif", "jpg" => "jpg.gif", "jpeg" => "jpg.gif", "png" => "png.gif", "" => "dir.gif", "shtml" => "shtml.gif", "txt" => "txt.gif", "text" => "txt.gif", "dir" => "dir.gif");

/* Default method of sorting, values can be: "alpha" for alphabetical sorting of the files names, "type" for alphabetical sorting of the file types, or "size" for sorting by file size. */
$sortby = "alpha";

// Alternation class name
$class = " class="odd"";

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Directory Listing of <?php echo($dir); ?></title>
<style type="text/css"><!--
/* General colors and layout */
body {
background-color: #DDD;
color: black;
font-family: arial, sans-serif;
font-size: small;
}
a:link {
color: black;
background-color:transparent;
}
a:visited {
color:dimgray;
background-color:transparent;
}
a:hover {
color: white;
background-color:transparent;
}
/* Table colors and layout */

tr {border-bottom:solid 1px black;}

table.dirList {
width: 100%;
color: black;
border:solid 1px black;
}
.dirList th {
color: black;
font-weight: normal;
background-color: #999;
font-size: 1.2em;
letter-spacing: -1px;
}
.dirList tr.odd {
color: black;
font-weight: normal;
background-color: #AAA;
padding-left: 1em;
padding-bottom: 0.2em;
}
.dirList tr {
color: black;
font-weight: normal;
background-color: #CCC;
padding-left: 1em;
padding-bottom: 0.2em;
}
--></style>
</head>
<body>
<table class="dirList" cellspacing="0" summary="A list of the files and folders located in this area of the site.">
<tr>
<th width="50%" style="text-align: center;">File Name</th>
<th width="10%" style="text-align: left;">File Type</th>
<th width="15%" style="text-align: right;">File Size</th>
<th width="8%" style="text-align: right;">Perms</th>
<th width="15%" style="text-align: right;">Last Modified</th>
</tr>
<?php

function du($location) {
if (!$location or !is_dir($location)) {
return 0;
}

$total = 0;

$all = opendir($location);
while ($file = readdir($all)) {
if (is_dir($location.'/'.$file) && $file != ".." && $file != ".") {
$total += du($location.'/'.$file);
unset($file);
}
elseif (!is_dir($location.'/'.$file)) {
$stats = stat($location.'/'.$file);
$total += $stats['size'];
unset($file);
}
}
closedir($all);
unset($all);
return number_format($total/1000, 2, '.', ',');
}


$dh = opendir($dir);
if(isset($_GET["sort"])){ $sortby = $_GET["sort"]; }
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}

for($k=0; $k<count($files); $k++){
$k2[] = explode(".", $files[$k]);
$k3[] = $k2[$k];
}
$k3 = array_slice($k3, 1);
for($b=0; $b<count($k3); $b++){
krsort($k3[$b]);
}
sort($k3);

if($sortby == "alpha")
{
sort($files);
for($f=0; $f<count($files); $f++)
{
$fType = explode(".", $files[$f]);
$fSize = filesize($files[$f])/1000;
if(!isset($fType[1]))
{
$_fSize = 0;
if($class != "")
{$class="";} else { $class=" class="odd"";}
echo("<tr".$class."><td><img src="". $icons["dir"] .""> <a href="". $files[$f] ."/">". $fType[0] ."</a></td>n");
echo("<td>Directory</td>");
echo("<td style="text-align:right;">". du($files[$f]) ." Kb</td>");
$perms = base_convert(fileperms($files[$f]), 10, 8);
$perms = substr($perms, (strlen($perms) - 3));
echo("<td style="text-align:right;">". $perms ."</td>");
$stat = stat($files[$f]);
echo("<td style="text-align:right;">". date("M. d, Y", $stat['mtime']) ."</td>");
}
}
for($f=2; $f<count($files); $f++)
{
$fType = explode(".", $files[$f]);
$fSize = number_format(filesize($files[$f])/1000, 2, '.', ',');
if(isset($fType[1]))
{
if(!isset($icons[$fType[1]]))
{ $icons[$fType[1]] = "unknown.gif"; }
if($class != "")
{$class="";} else { $class=" class="odd"";}
echo("<tr".$class."><td><img src="". $icons[$fType[1]] .""> <a href="". $files[$f] ."">". $fType[0] ."</a></td>n");
echo("<td>". strtoupper($fType[1]) ."</td>n");
echo("<td style="text-align: right">". $fSize ." Kb</td>");
$perms = base_convert(fileperms($files[$f]), 10, 8);
$perms = substr($perms, (strlen($perms) - 3));
echo("<td style="text-align:right;">". $perms ."</td>");
$stat = stat($files[$f]);
echo("<td style="text-align:right;">". date("M. d, Y", $stat['mtime']) ."</td>");
}
}
}

if($sortby == "type")
{
for($a=0; $a<count($k3); $a++)
{
if(!empty($k3[$a][1]) && !empty($k3[$a][0]))
{
$fSize = filesize($k3[$a][0] .".". $k3[$a][1]) /1000;
if($class != "")
{$class="";} else { $class=" class="odd"";}
echo("<tr ". $class.">n<td><img src="". @$icons[$k3[$a][1]] .""> <a href="". $k3[$a][0] .".". $k3[$a][1] ."">". $k3[$a][0] ."</a></td>n");
echo("<td>". strtoupper($k3[$a][1]) ."</td>n");
echo("<td style="text-align: right;">". $fSize ." Kb</td>n");
$perms = base_convert(fileperms($k3[$a][0].".".$k3[$a][1]), 10, 8);
$perms = substr($perms, (strlen($perms) - 3));
echo("<td style="text-align:right;">". $perms ."</td>n");
$stat = stat($k3[$a][0].".".$k3[$a][1]);
echo("<td style="text-align:right;">". date("M. d, Y", $stat['mtime']) ."</td>n</tr>n");
} else {
$_fSize = du($k3[$a][0]);
if(!empty($k3[$a][0]))
{
if($class != "")
{$class="";} else { $class=" class="odd"";}
echo("<tr ". $class .">n<td><img src="". $icons['dir'] .""> <a href="". $k3[$a][0] ."/">". $k3[$a][0] ."</a></td>n");
echo("<td>Directory</td>n");
echo("<td style="text-align: right;">". $_fSize ." Kb</td>n");
$perms = base_convert(fileperms($k3[$a][0]), 10, 8);
$perms = substr($perms, (strlen($perms) - 3));
echo("<td style="text-align:right;">". $perms ."</td>n");
$stat = stat($k3[$a][0]);
echo("<td style="text-align:right;">". date("M. d, Y", $stat['mtime']) ."</td>n</tr>n");
}
}
}
}
?>
</table>
<div style="background-color: #AAA; color: black; padding: 2px; border: solid 1px black; font-size: small;">
<p>Processing time: <?php echo(time() - $sTime); ?> seconds.</p>
<p>This document, located at <span style="font-family:monospace;"><?php echo($dir . str_replace("/", "\", $_SERVER["PHP_SELF"])); ?></span>, was last modified on <?php echo(date("M d, Y", getlastmod())); ?>.</p>
<p>Powered by...<br>
<a href="http://www.php.net/" title="Go to PHP.net"><img src="<?php echo($_SERVER["PHP_SELF"] . "?=". php_logo_guid()); ?>" alt="Powered by PHP version <?php echo(phpversion()); ?>!" style="border:none;"></a> <a href="http://www.zend.com/" title="Go to Zend.com"><img src="<?php echo($_SERVER["PHP_SELF"]."?=". zend_logo_guid()); ?>" alt="Powered by Zend version <?php echo(zend_version()); ?>!"></a></p>
<p style="margin-top: -50px; text-align: right;">
<a href="index.php?phpinfo">PHP Information</a> |
<a href="index.php?extns">Installed PHP Extensions</a> |
<a href="index.php?sort=alpha">Sort Alphabetically</a> |
<a href="index.php?sort=type">Sort by Type</a></p>
<br></div>
</body></html> [/code]


thanks to jona



[B]Sheldon[/B]
Copy linkTweet thisAlerts:
@SheldonMay 18.2005 — sorry for my poor post [b] bad { instead of [, blam beer, but i know you cant blame beer[/B]


Sheldon
Copy linkTweet thisAlerts:
@DariaauthorJul 28.2005 — Sorry, I Zoned Out Of This Thread!!!

Thanks, People ?
Copy linkTweet thisAlerts:
@BeachSideJul 28.2005 — Sorry, I Zoned Out Of This Thread!!!

Thanks, People ?[/QUOTE]


Months ago LoL :p
×

Success!

Help @Daria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...