
July 3rd, 2009, 11:52 AM
|
|
|
Function to create a gallery
Hallo to everybody,
I’ve create this code… but it gave me a problem… I’m new in php so I don’t see the error… when I’m wrong? This a part of a gallery that I described here http://forums.devshed.com/beginner-programming-16/it-s-possible-618899.html.
Thank you to all and a good week!
PHP Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento senza titolo</title>
<?php
function dir_reader($dir, &$images, &$subdirs)
{
//Creo la funzione per la lettura nelle cartelle e nelle sottocartelle
global $defdir;
$dir= dir(My_Gallery);
if($dir != $defdir)
{
$dir = $defdir."/".$dir;
}
header('Content-type:text/xml'); //Dichiarazione dell'xml
$xml="<galleria>"; //nome dell'xml
//apro la directory madre
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
//Assegno le variabili e Divido le stringhe
list($file, $ext) = explode(".", $file);
if(!is_dir($dir.'/'.$file))
{
//Specifico le estensioni dei file
if($ext == "jpg" || $ext == "jpeg")
{
$images[] = $file;
}
{
$xml.= "pic image= \"../My_Gallery/$images\"/>\n";
}
}
else
{
//Creo i link di collegamento
$subdirs[] = "<a href='?My_Gallery=".$file."'>".$file."</a>";
}
}
}
//Chiudo la cartella madre
closedir($handle);
}
echo $xml;
//Nome della cartella madre
$defdir = './My_Gallery';
if(!isset($_GET['My_Gallery']))
{
$dir = $defdir;
}
else
{
$dir = $_GET['My_Gallery'];
}
$images = array();
$subdirs = array();
dir_reader($dir, $images, $subdirs);
?>
<table border="2">
<tr>
<td>
<?php
// Includo la funzione random per le immagini
include "immagini_random.php"
//Includo la funzione per creazione di link
?>
</td>
<td>
<?php
header (Content_type
// Inserisco il codice per la creazione della gallery e prelevamento dati per flash
while (list($chiave,$valore)= each($images))
{
echo"$valore </br>";
echo "<img src=$images>";
$numero_elementi=count($images);
echo "&numero_elementi=".$numero_elementi;
for ($i=0;$i<$numero_elementi;$i++)
echo '&images_" .$i ."=" .$images[$i]';
}
}
$xml.="</galleria>";
?>
</td>
</tr>
</table>
</head>
</html>
Bye
Last edited by aitken325i : July 4th, 2009 at 09:37 AM.
Reason: Fixed PHP Tags
|