:: Anbieterverzeichnis :: Globale Branchen
:: SELFPHP Forum ::
Fragen rund um die Themen PHP?
In über
130.000 Beiträgen finden Sie sicher die passende
Antwort! 
:: Newsletter ::
Abonnieren Sie hier den kostenlosen
SELFPHP Newsletter!
|
|
Bilderverzeichnis mit Menge und Größe aller Bilder anzeigen  |
|
SELFPHP ist Shopware Solution Partner
Shopware ist ein vielfach ausgezeichnetes Onlineshop-System der shopware AG, das auf PHP. Zend Framework und SQL basiert.
SELFPHP unterstützt Sie als Shopware Solution Partner bei der Konzeption, Programmierung und Realisierung Ihres Onlineshops und passt Shopware bei Bedarf an Ihre Unternehmensbedürfnisse an.
Weitere Informationen
Beispielaufgabe
Bilderverzeichnis mit Menge und Größe aller Bilder anzeigen
Beschreibung
Nachfolgend möchten wir Ihnen ein Programm vorstellen, mit dem Sie eine Übersichtsseite für eine Bildergalerie erstellen können. Das Programm durchläuft dabei alle angegebenen Verzeichnisse und zählt jeweils die Menge, sowie die Gesamtgröße aller Bilder in dem jeweiligen Verzeichnis. Zusätzlich wird für jedes Verzeichnis ein Vorschaubild dynamisch erstellt und angezeigt.
Durch einen Klick auf ein Verzeichnisbild, werden alle Bilder des Verzeichnisses aufgelistet und als Originalbild angezeigt.
Folgende Funktionalitäten beinhaltet unser Beispiel:
+ Datenbankunterstützung
+ Angabe eines Verzeichnisnamen
+ Anzahl aller Bilder in einem Verzeichnis
+ Gesamtgröße aller Bilder in einem Verzeichnis
+ Vorschaubild für jedes Verzeichnis
+ Anzeige aller Bilder eines Verzeichnisses
+ Anzeige der Dimension (Pixel) aller Bilder
+ Anzeige des Originalbildes
+ Anzeige des Bildnamens
Download der Dateien
Datei: imagefolder.php
<?php
/**
* ImageFolder
*
* @package ImageFolder
* @author Damir Enseleit
* @copyright 2012, SELFPHP OHG
* @license MIT
* @version 1.0.0
* @link http://www.selfphp.de
*
*/
function dir_size($dir) {
$images = array();
$images['file'] = '';
$images['size'] = 0;
$images['filesCount'] = 0;
$handle = @opendir($dir);
if(!$handle)
return false;
while ($file = @readdir ($handle)) {
if ($file == "." || $file == "..") {
continue;
}
if (!is_dir($dir . DIRECTORY_SEPARATOR . $file)){
$images['size'] += filesize($dir . DIRECTORY_SEPARATOR . $file);
$images['filesCount'] += 1;
$images['file'] = $dir . DIRECTORY_SEPARATOR . $file;
}
}
@closedir($handle);
$images['size'] = sizeMath($images['size']);
return $images;
}
function sizeMath($size) {
if($size >= 1000000) {
$size = $size / 1000000;
$size = round($size) . 'MB';
} else {
$size = $size / 1000;
$size = round($size) . 'KB';
}
return $size;
}
function getPictures($dir){
$handle = @opendir($dir);
$files = array();
$counter = 0;
if(!$handle)
return false;
while ($file = @readdir ($handle)) {
if ($file == "." || $file == "..") {
continue;
}
if (!is_dir($dir . DIRECTORY_SEPARATOR . $file)){
$files[$counter]['file'] = $file;
$files[$counter]['size'] = sizeMath(filesize($dir . DIRECTORY_SEPARATOR . $file));
$dimension = getimagesize($dir . DIRECTORY_SEPARATOR . $file);
$files[$counter]['width'] = $dimension[0];
$files[$counter]['height'] = $dimension[1];
$counter++;
}
}
@closedir($handle);
return $files;
}
?>
|
Datei: create_thumb.php
<?php
function resizePicture($file, $width, $height)
{
if(!file_exists($file))
return false;
header('Content-type: image/jpeg');
$info = getimagesize($file);
if($info[2] == 1)
{
$image = imagecreatefromgif($file);
}
elseif($info[2] == 2)
{
$image = imagecreatefromjpeg($file);
}
elseif($info[2] == 3)
{
$image = imagecreatefrompng($file);
}
else
{
return false;
}
if ($width && ($info[0] < $info[1]))
{
$width = ($height / $info[1]) * $info[0];
}
else
{
$height = ($width / $info[0]) * $info[1];
}
$imagetc = imagecreatetruecolor($width, $height);
imagecopyresampled($imagetc, $image, 0, 0, 0, 0, $width, $height,
$info[0], $info[1]);
imagejpeg($imagetc, null, 100);
// Den Speicher freigeben
imagedestroy($imagetc);
}
$width = 160;
$height = 110;
resizePicture($_GET['file'], $width, $height);
?>
|
Datei: images.php
Anwendungsbeispiel
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unbenanntes Dokument</title>
<style>
body{
color:#666;
}
.picturebox{
width: 180px;
height: 250px;
border: #cac9c9 1px solid;
float:left;
margin-right:10px;
}
.thumb{
height: 201px;
border-bottom: #cac9c9 1px solid;
padding:5px;
text-align:center;
}
.boxleft { float: left;
border-right: #cac9c9 1px solid;
}
.boxleft, .boxright, .boxmiddle{
padding:3px;
text-align:center;
font:"Courier New", Courier, monospace;
font-size:12px;
}
.boxright { float: right;
}
.boxleft, .boxright { width: 27%; }
.boxmiddle { margin: 0 33%;
border-right: #cac9c9 1px solid;
}
.picturebox span{
float:left;
}
.thumb img{
border: #cac9c9 1px solid;
padding:2px;
margin-top: 10px;
}
.thumb button{
margin-top: 10px;
}
.boxright a{
margin-top: 5px;
}
.boxright img{
margin-top:5px;
}
</style>
</head>
<body>
<?php
include_once("dbconnect.php");
include_once("imagefolder.php");
$imageFolder = "images" . DIRECTORY_SEPARATOR;
$result = @mysql_query("SELECT * FROM `imagefolder` WHERE 1");
$num = @mysql_num_rows($result);
for( $x = 0; $x < $num; $x++ ){
$folder = $imageFolder . @mysql_result( $result, $x, "path");
$images = dir_size( $folder );
if (empty($images['file']))
$images['file'] = 'no-photo.png';
?>
<div class="picturebox">
<div class="thumb"><?php echo @mysql_result( $result, $x, "foldername"); ?><br>
<a href="showimages.php?id=<?php echo @mysql_result( $result, $x, "id"); ?>">
<img src="create_thumb.php?file=<?php echo $images['file']; ?>" border="0"></a>
</div>
<div class="boxleft"><?php echo $images['filesCount']; ?><br>Dateien</div>
<div class="boxright">
<a href="showimages.php?id=<?php echo @mysql_result( $result, $x, "id"); ?>">
<img src="folder.png" border="0"></a></div>
<div class="boxmiddle"><?php echo $images['size']; ?><br>Gesamt</div>
</div>
<?php
}
?>
</body>
</html>
|
Datei: showimages.php
Anwendungsbeispiel
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unbenanntes Dokument</title>
<style>
body{
color:#666;
}
.picturebox{
width: 180px;
height: 250px;
border: #cac9c9 1px solid;
float:left;
margin-right:10px;
}
.thumb{
height: 201px;
border-bottom: #cac9c9 1px solid;
padding:5px;
text-align:center;
}
.boxleft { float: left;
border-right: #cac9c9 1px solid;
}
.boxleft, .boxright, .boxmiddle{
padding:3px;
text-align:center;
font:"Courier New", Courier, monospace;
font-size:12px;
}
.boxright { float: right;
}
.boxleft, .boxright { width: 27%; }
.boxmiddle { margin: 0 33%;
border-right: #cac9c9 1px solid;
}
.picturebox span{
float:left;
}
.thumb img{
border: #cac9c9 1px solid;
padding:2px;
margin-top: 10px;
}
.thumb button{
margin-top: 10px;
}
.boxright a{
margin-top: 5px;
}
.boxright img{
margin-top:5px;
}
.infopic{
margin-top:8px;
font-size:13px;
}
</style>
</head>
<body>
<?php
include_once("dbconnect.php");
include_once("imagefolder.php");
$imageFolder = "images" . DIRECTORY_SEPARATOR;
$id = $_GET['id'] + 0;
$result = @mysql_query("SELECT * FROM `imagefolder` WHERE id = " . $id);
$num = @mysql_num_rows($result);
if ( $num == 1 ){
$folder = $imageFolder . @mysql_result( $result, 0, "path");
$getAllPictures = getPictures( $folder );
for( $x = 0; $x < count($getAllPictures); $x++ )
{
$folderImage = $folder . DIRECTORY_SEPARATOR . $getAllPictures[$x]['file'];
$image = "images/" . @mysql_result( $result, 0, "path") . "/" . $getAllPictures[$x]['file'];
?>
<div class="picturebox">
<div class="thumb"><?php echo $getAllPictures[$x]['file']; ?><br>
<a href="<?php echo $image; ?>" target="_blank">
<img src="create_thumb.php?file=<?php echo $folderImage; ?>" border="0"></a>
<div class="infopic">
<?php echo $getAllPictures[$x]['width']; ?> x <?php echo $getAllPictures[$x]['height']; ?> Pixel
</div>
</div>
<div class="boxleft"> <br> </div>
<div class="boxright"><!-- Button --><a href="<?php echo $image; ?>" target="_blank">
<img src="folder.png" border="0"></a></div>
<div class="boxmiddle"><?php echo $getAllPictures[$x]['size']; ?><br>Größe</div>
</div>
<?php
}
}
?>
</body>
</html>
|
Ausgabebeispiel: Browseransicht

|
|
|
|
|


:: Anbieterverzeichnis ::
Webhosting/Serverlösungen
Suchen Sie den für Sie passenden IT-Dienstleister für Ihr Webhosting-Paket oder Ihre Serverlösung?
Sie sind nur ein paar Klicks davon entfernt! 
SELFPHP Code Snippet
Bit in Byte umrechnen
Weitere interessante Code Snippets finden Sie auf SELFPHP im Bereich PHP Code Snippets
|