Hallo Leute!
Ich hoffe, ihr könnt mir helfen, denn ich komme trotz googeln nicht auf den Fehler ... Und zwar habe ich ein neues Layout gemacht, auf dem links oben ein Bild, quasi ein Header, ist. Durch aktualisieren oder anklicken einer Unterseite soll sich das Bild ändern, was eigentlich auch prima funktioniert.
Für dieses Feature habe ich einen php Code verwendet, und zwar folgenden:
<?php
function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images;}
function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); // php 4.2+ not needed $num = array_rand($ar); return $ar[$num];}
/////////////////////////////////////////////////////////////////////// This is the only portion of the code you may need to change.// Indicate the location of your images
$root = '';// use if specifying path from root//$root = $_SERVER['DOCUMENT_ROOT'];
<?php
function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images;}
function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); // php 4.2+ not needed $num = array_rand($ar); return $ar[$num];}
/////////////////////////////////////////////////////////////////////// This is the only portion of the code you may need to change.// Indicate the location of your images
$root = '';// use if specifying path from root//$root = $_SERVER['DOCUMENT_ROOT'];
$path = 'img/3/';
// End of user modified section /////////////////////////////////////////////////////////////////////
// Obtain list of images from directory $imgList = getImagesFromDir($root . $path);$img = getRandomFromArray($imgList);?>
// End of user modified section /////////////////////////////////////////////////////////////////////
// Obtain list of images from directory $imgList = getImagesFromDir($root . $path);$img = getRandomFromArray($imgList);?>
Alles anzeigen
Mir ist klar, dass "$path = 'img/3/';" den Pfad des Ordners angibt, in dem die Bilder drinnen sind und wenn ich das so stehen lasse, dann funktioniert das auf der Startseite auch ganz gut. (sprich so: http://i40.tinypic.com/13zy2qx.pn ). Wenn ich dann eine Unterseite aufrufe (in meinem Fall wars "Site"), dann sieht es so aus: http://i40.tinypic.com/23mlfl5.png (ich nehme an, dass es daran liegt, weil der Browser nicht mehr versucht "http://url.com/img/3/header1.png" aufzurufen sondern "http://url.com/site/img/3/header1.png" und das existiert ja nicht bei mir)
Okay, das fand ich schon sehr komisch. Ich dachte, das läge daran, dass nicht der komplette Pfad geschildert worden ist (also die komplette URL), sondern eben nur der Ordner, in dem die Bilder drinnen sind. Aber wenn ich die Adresse komplett ausschreibe, wird nicht einmal mehr auf der Startseite das Bild angezeigt und ich glaube, dass hier der Knackpunkt liegt, an dem ich einfach nicht komme. Hat jemand Ideen, was man dabei tun könnte? Ich würde mich über jede Hilfe freuen :)