mediengestalter.info
FAQ :: Mitgliederliste :: MGi Team

Willkommen auf dem Portal für Mediengestalter

Aktuelles Datum und Uhrzeit: Di 23.04.2024 23:05 Benutzername: Passwort: Auto-Login

Thema: dynamische Slideshow mit php & xml vom 30.01.2006


Neues Thema eröffnen   Neue Antwort erstellen MGi Foren-Übersicht -> Programmierung -> dynamische Slideshow mit php & xml
Autor Nachricht
redfoxcorp
Threadersteller

Dabei seit: 30.01.2006
Ort: -
Alter: -
Geschlecht: -
Verfasst Mo 30.01.2006 20:41
Titel

dynamische Slideshow mit php & xml

Antworten mit Zitat Zum Seitenanfang

Folgendes problem habe ich:
Ich habe mir ein php script gebastelt welches mir die verzeichnisstrucktur ab einer betimmten ebene ausließt und daraus eine xml-datei erzeugt seltsamer weise funzt das mit dem ersten ordner problemlos doch ab dem zweiten tauchen mit einem mal die bildeinträge dreimal auf siehe beispiel:

images.xml

Code:

<?xml version="1.0" encoding="UTF-8"?>
<gallery>
     <album id="website1.com" title="website1.com" lgPath="./ssp/gallery/website1.com/" description="Promotingpics
        of www.website1.com">
         <img src="1.jpg" link="./ssp/gallery/website1.com/1.html" caption="Please visit: www.website1.com" />
         <img src="2.jpg" link="./ssp/gallery/website1.com/2.html" caption="Please visit: www.website1.com" />
         <img src="3.jpg" link="./ssp/gallery/website1.com/3.html" caption="Please visit: www.website1.com" />
     </album>
     <album id="website2.com" title="website2.com" lgPath="./ssp/gallery/website2.com/" description="Promotingpics
        of www.website2.com">
         <img src="1.jpg" link="./ssp/gallery/website2.com/1.html" caption="Please visit: www.website2.com" />
         <img src="2.jpg" link="./ssp/gallery/website2.com/2.html" caption="Please visit: www.website2.com" />
         <img src="3.jpg" link="./ssp/gallery/website2.com/3.html" caption="Please visit: www.website2.com" />
         <img src="1.jpg" link="./ssp/gallery/website2.com/1.html" caption="Please visit: www.website2.com" />
         <img src="2.jpg" link="./ssp/gallery/website2.com/2.html" caption="Please visit: www.website2.com" />
         <img src="3.jpg" link="./ssp/gallery/website2.com/3.html" caption="Please visit: www.website2.com" />
         <img src="1.jpg" link="./ssp/gallery/website2.com/1.html" caption="Please visit: www.website2.com" />
         <img src="2.jpg" link="./ssp/gallery/website2.com/2.html" caption="Please visit: www.website2.com" />
         <img src="3.jpg" link="./ssp/gallery/website2.com/3.html" caption="Please visit: www.website2.com" />
     </album>
</gallery>


das ist schonmal das erste prob ich weiß nicht woran das liegen könnte ...
und das zweite prob die pics sollen beim draufklicken in vergrößerter form dargestellt werden alles kein prob nur möchte ic[/code]h nicht jedesmal die htmlseiten per hand erzeugen sondern das am besten ebenfalls vom php-script machen lassen.

Achso hier erstmal das php-script von mir was so leicht buggi ist Ooops

make.php

Code:

<?php
//File where all album folders and files are listen
$fn="images.xml";
$fp=fopen($fn,"w");

//Directory where all album folders are located
$albums_dir = './ssp/gallery/';

//Get directories for photo albums
$d = dir($_SERVER['DOCUMENT_ROOT'].$albums_dir);
while (false !== ($entry = $d->read())) {
   if(is_dir($d->path.'/'.$entry) && $entry != '.' && $entry != '..') {
      $albums[] = $entry;
   }
}
$d->close();

//Send content type as text/xml so the browser knows it's an xml file
header('Content-type: text/xml');

//Generate xml data
fwrite($fp,'<?xml version="1.0" encoding="utf-8"?>');
fclose($fp);
$fp=fopen($fn,"a");
fwrite($fp,'<gallery>');
for($i = 0; $i < sizeof($albums); $i++) {
   $album_title = ucwords(eregi_replace('_',' ',$albums[$i])); //Remove underscores and capitalize the words in the album directory
   fwrite($fp,'  <album title="'.$album_title.'" description="" lgPath=".'.$albums_dir.''.$albums[$i].'/">');
   
   // Load all photos for this album into an array, then print them out
   $album_photos_dir = $_SERVER['DOCUMENT_ROOT'].$albums_dir.'/'.$albums[$i].''; 
   $dh  = opendir($album_photos_dir);
   while (false !== ($filename = readdir($dh))) {
      if (eregi("jpg",$filename)) {
         $album_photos[] = $filename;
      }
   }
   for($j = 0; $j < sizeof($album_photos); $j++) {
      fwrite($fp,'    <img src="'.$album_photos[$j].'" caption="Please visit: www.'.$albums[$i].'" link="" />');
   }
   fwrite($fp,'  </album>');
}
fwrite($fp,'</gallery>');
fclose($fp);

?>
[/
code]
  View user's profile Private Nachricht senden
redfoxcorp
Threadersteller

Dabei seit: 30.01.2006
Ort: -
Alter: -
Geschlecht: -
Verfasst Do 02.02.2006 04:57
Titel

Antworten mit Zitat Zum Seitenanfang

also wens intressiert ...
bin selber drauf gekommen was der fehler war.
funzt nun alles wie es soll. hier das script für die die vielleicht noch am grübeln sind...




Code:

<?php
//Directory where all album folders are located
$albums_dir = '/ssp/gallery/';
//XML-File
$xmlFile = 'images.xml';
$xmlPath = '../';

//Get directories for photo albums
$d = dir($_SERVER['DOCUMENT_ROOT'].$albums_dir);
while (false !== ($entry = $d->read())) {
   if(is_dir($d->path.'/'.$entry) && $entry != '.' && $entry != '..') {
        $albums[] = $entry;
    }
}
$d->close();

//Send content type as text/xml so the browser knows it's an xml file
header('Content-type: text/xml');

// start xml output variable
    $output .= '<?xml version="1.0"?>';
    $output .= '<gallery>';
// Prevent PHP from timing out on large folders
    set_time_limit(0);

for($i = 0; $i < sizeof($albums); $i++) {
//Remove underscores and capitalize the words in the album directory
    $album_title = ucwords(eregi_replace('_',' ',$albums[$i]));
    $output .= '<album title="'.$album_title.'" description="" lgPath="'.$albums_dir.''.$albums[$i].'/">';
// Load all photos for this album into an array, then print them out
    $album_photos_dir = $_SERVER['DOCUMENT_ROOT'].$albums_dir.'/'.$albums[$i].''; 
    $dh  = opendir($album_photos_dir);
    while (false != ($filename = readdir($dh))) {
       
        if (eregi("jpg",$filename)) {
        $output .= '<img src="'.$filename.'" caption="Please visit: <a href="http://www." target="_blank">www.</a>'.$albums[$i].'" link="'.$albums_dir.''.$albums[$i].'/'.$filename.'" />';
        }
    }


    $output .= '</album>';
}

$output .= '</gallery>';

        // Attempt to open the xml file for writing (will be created if it doesn't exist)
        if(!$xml = @fopen($xmlPath."/".$xmlFile, "w")) {
              echo '<p>Error: '.$xmlPath."/".$xmlFile.' file could not be opened for writing. <br />';
            echo 'Check to be sure either the permissions for the folder are set to 777 or, if the xml<br />';
            echo 'file already exists, that it is set to 777.</p>';
        } else {
       
            // Write the xml file
            if (fwrite($xml, $output) === FALSE) {
                echo '<p>Error: Unable to write to file.</p>';
            } else {
             
                fclose($xml);
            }
       
        }
?>






PS: wenn jemand vorschläge zur verbesserung des Codes hat
(sauberere schreibweise) hab ich gern ein offenes ohr..
  View user's profile Private Nachricht senden
Anzeige
Anzeige
 
Ähnliche Themen Dynamische Flash Slideshow
[jQuery Cycle] Slideshow in Slideshow wechseln zusammen
Dynamische HP
Dynamische PDF ?
<div> dynamische Größe??
css dynamische seitenlayouts
Neues Thema eröffnen   Neue Antwort erstellen
MGi Foren-Übersicht -> Programmierung


Du kannst keine Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum nicht antworten.
Du kannst an Umfragen in diesem Forum nicht mitmachen.