PHP slideshow

Tags:    php

Hej alle

Har et spørgsmål om et slideshow, måske der er et der kan hjælp med??

Nedstående kode virker fint, men det kræver at det er i dette mappe hvor der skal vises billeder fra.

Jeg vil gerne have at jeg kan include() det i forskellige sider og vis billeder fra bestemt mapper.

er der en der kan hjælp????

På forhånd TAK.

<?php
$include = "_include/";

$headline = "Lytzen IT - Om Lyten IT";
$photosby = "photos from the world wide web";
$autostart = true; // true; or false;
$slideeffect = "5"; // "0"; - "15";
// Slideeffects: 0=Blend, 1=Blinds, 2=Checker, 3=Diagonal, 4=Doors,
// 5=Gradient, 6=Iris, 7=Pinwheel, 8=Pixelate, 9=Radial,
// 10=Rain, 11=Slide, 12=Snow, 13=Spiral, 14=Stretch, 15=RANDOM!
$slidedirection = "up"; // "up"; or "down";

// Visit http://dl.pixary.net/slideme.html for more information.
?>

<!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=iso-8859-1" />
<meta name="keywords" content="slideme smig image gallery 1.0 gallerie galerie javascript javaskript js">
<meta name="description" content=":SlideMe Image Gallery 1.0 - the gallery with slideeffects!">
<meta name="author" content="Mario B. - Pixary.net">
<title>:SlideMe - Image Gallery 1.0</title>
<link rel="stylesheet" type="text/css" href="<?php echo $include ?>style.css" />
<script language="javascript" src="<?php echo $include ?>sniffer.js"></script>
</head>

<body <?php if ($autostart == true) {echo "onload='stopOrStart();'";} ?> >
<script language="JavaScript">
var timer;
var current_location = 1;
var next_location = 1;
var pics_loaded = 0;
var onoff = 0;
var timeout_value;
var images = new Array;
var photo_urls = new Array;
var photo_captions = new Array;
var photo_comment = new Array;
var photo_user_epic_comment = new Array;
var transitionNames = new Array;
var transitions = new Array;
var loop = 1;
var current_transition = <?php echo $slideeffect;?>;
var direction = <?php if ($slidedirection == "up") {echo "1";} if ($slidedirection == "down") {echo "-1";} ?>;

<?php
$handle = opendir('.');
$c=1;
while ($file = readdir ($handle)) {
if($file != "." && $file != ".."){
if(preg_match("/.(jpg|gif|png)$/i", $file)){
$fileArray[] = $file;
}
}
}
closedir($handle);
asort($fileArray);
foreach($fileArray as $row) {
echo "photo_urls[".$c."] = '".$row."';";
$c++;
}
$countimg = count($fileArray);
?>

transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
transitions[1] = "progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)";
transitions[2] = "progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)";
transitions[3] = "progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)";
transitions[4] = "progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)";
transitions[5] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
transitions[6] = "progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)";
transitions[7] = "progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)";
transitions[8] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
transitions[9] = "progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)";
transitions[10] = "progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)";
transitions[11] = "progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)";
transitions[12] = "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)";
transitions[13] = "progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)";
transitions[14] = "progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)";
transitions[15] = "special case";
var transition_count = 15;

var photo_count = <?php echo $countimg; ?>;
var slideShowLow = "";
var browserCanBlend = (is_ie5_5up);


function stopOrStart() {
if (onoff) {
stop();
} else {
play();
}
}

function toggleLoop() {
if (loop) {
loop = 0;
} else {
loop = 1;
}
}

function changeElementText(id, newText) {
element = document.getElementById(id);
element.innerHTML = newText;
}

function stop() {
changeElementText("stopOrStartText", "Start Slideshow");
changeElementText("changeDirText", " ");

if (browserCanBlend) {
changeElementText("time", " ");
changeElementText("fading", " ");
}

onoff = 0;
clearTimeout(timer);
}

function play() {
changeElementText("stopOrStartText", "Pause");

if (browserCanBlend) {
if (!onoff) {
if (direction==1)
changeElementText("changeDirText", "<img src='<?php echo $include; ?>change.png' border='0'>");
else
changeElementText("changeDirText", "<img src='<?php echo $include; ?>backward.png' border='0'>");
changeElementText("time", "<select name='time' onchange='play()' class='timebox'><option value='1'> 1 Second<option value='2'> 2 Seconds<option value='3' selected> 3 Seconds<option value='5' > 5 Seconds<option value='10'> 10 Seconds</select>");
changeElementText("fading", "<select name='transitionType' onchange='change_transition()' class='fadebox'><option value='0' selected> Blend <option value='1'> Blinds <option value='2'> Checker <option value='3'> Diagonal <option value='4'> Doors <option value='5'> Gradient <option value='6'> Iris <option value='7'> Pinwheel <option value='8'> Pixelate <option value='9'> Radial <option value='10'> Rain <option value='11'> Slide <option value='12'> Snow <option value='13'> Spiral <option value='14'> Stretch <option value='15'> RANDOM! </select>");
}
}
onoff = 1;
go_to_next_photo();
}

function next() {
direction = 1;
next_location = (parseInt(current_location) + parseInt(direction));

if (next_location > photo_count) {
next_location = 1;
if (!loop) {
stop();
}
}
if (next_location == 0) {
next_location = photo_count;
if (!loop) {
stop();
}
}
current_location=next_location;
preload_photo(current_location);

document.slide.src = images[current_location].src;
setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
if (onoff==1)
stop();
}

function back() {
direction = -1;
next_location = (parseInt(current_location) + parseInt(direction));
if (next_location > photo_count) {
next_location = 1;
if (!loop) {
stop();
}
}
if (next_location == 0) {
next_location = photo_count;
if (!loop) {
stop();
}
}
current_location = next_location;
preload_photo(current_location);

document.slide.src = images[current_location].src;
setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
if (onoff==1)
stop();
}

function weiter() {
direction = 1;
next_location = (parseInt(current_location) + parseInt(direction));
if (next_location > photo_count) {
next_location = 1;
if (!loop) {
stop();
}
}
if (next_location == 0) {
next_location = photo_count;
if (!loop) {
stop();
}
}
current_location=next_location;
preload_photo(current_location);

document.slide.src = images[current_location].src;
setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
if (onoff==1)
stop();
}

function changeDirection() {
if (direction == 1) {
direction = -1;
changeElementText("changeDirText", "<img src='<?php echo $include; ?>backward.png' border='0'>");
} else {
direction = 1;
changeElementText("changeDirText", "<img src='<?php echo $include; ?>forward.png' border='0'>");
}
setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
preload_next_photo();

}

function change_transition() {
current_transition = document.smigform.transitionType.selectedIndex;
}

function preload_complete() {}

function reset_timer() {
clearTimeout(timer);

if (onoff) {
timeout_value = document.smigform.time.options[document.smigform.time.selectedIndex].value * 1000;
timer = setTimeout('go_to_next_photo()', timeout_value);
}
}

function wait_for_current_photo() {
if (!show_current_photo()) {
status = "Picture is loading...(" + current_location + " of " + photo_count + "). Please wait!" ;
clearTimeout(timer);
timer = setTimeout('wait_for_current_photo()', 505);
return 0;
}
else {
status = "Slideshow is running...";
preload_next_photo();
reset_timer();
}
}

function go_to_next_photo() {
current_location = next_location;

if (!show_current_photo()) {
wait_for_current_photo();
return 0;
}

preload_next_photo();
reset_timer();
}

function preload_next_photo() {
next_location = (parseInt(current_location) + parseInt(direction));
if (next_location > photo_count) {
next_location = 1;
if (!loop) {
stop();
}
}
if (next_location == 0) {
next_location = photo_count;
if (!loop) {
stop();
}
}
preload_photo(next_location);
}

function show_current_photo() {
if (!images[current_location] || !images[current_location].complete) {
preload_photo(current_location);
return 0;
}

if (browserCanBlend){
var do_transition;
if (current_transition == (transition_count)) {
do_transition = Math.floor(Math.random() * transition_count);
} else {
do_transition = current_transition;
}
document.images.slide.style.filter=transitions[do_transition];
document.images.slide.filters[0].Apply();
}
document.slide.src = images[current_location].src;
setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);

if (browserCanBlend) {
document.images.slide.filters[0].Play();
}
return 1;
}

function preload_photo(index) {

if (pics_loaded < photo_count) {

if (!images[index]) {
images[index] = new Image;
images[index].onLoad = preload_complete();
images[index].src = photo_urls[index];
pics_loaded++;
}
}
}

function setCaption(text,comment,user_comment) {
changeElementText("caption", "Picture " + current_location + " of " + photo_count + " ");
}
</script>

<form name='smigform'>

<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">

<div class="headline"><?php echo $headline ?></div>
<script language="JavaScript">
document.write("<font class='pixcount' id='caption';></font>");
</script>
</div>
</td>
<td> </td>
</tr>
<tr>
<td colspan="2">
<div class="navigation">
<div class="navitext" style="width:60px;"><a href='#' onClick='back(); return false;'><img src="<?php echo $include; ?>preview.png" border="0" /></a></div>
<div class="navitext" style="width:110px;"><a href='#' onClick='stopOrStart(); return false;'><span id='stopOrStartText'>Start Slideshow</span></a></div>
<div class="navitext" style="width:60px;"><a href='#' onClick='next(); return false;'><img src="<?php echo $include; ?>next.png" border="0" /></a></div>
<div class="navitext" style="width:60px;"><a href='#' onClick='changeDirection(); return false;'><span id='changeDirText'></span></a></div>
<div style="float:left;">
<span id="time">
<script language="JavaScript">
if (!browserCanBlend) {document.write("<select name='time' onchange='play()'><option value='1'> 1 Second<option value='2'> 2 Seconds<option value='3' selected> 3 Seconds<option value='5' > 5 Seconds<option value='10'> 10 Seconds</select>"); }
</script>
</span>
<span id="fading"></span> </div>
<div><a href='#' onClick='changeDirection(); return false;'><span id='changeDirText'></span></a></div>
</div> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center">
<script language="JavaScript">
document.write("<a href='javascript:weiter()'><img src="+photo_urls[1]+" name='slide' class='photostyle'></a>");
</script></td>
<td> </td>
</tr>
<tr>
<td align="left">

<a href="http://dl.pixary.net" target="_blank"><img src="http://dl.pixary.net/slideme.gif" border="0" /></a>
</td>
<td align="right" class="photosby"><?php echo $photosby ?></td>
<td> </td>
</tr>
</table>

<script language="Javascript">
setCaption(photo_urls[1]);
</script>

</form>
</body>
</html>



3 svar postet i denne tråd vises herunder
1 indlæg har modtaget i alt 2 karma
Sorter efter stemmer Sorter efter dato
denne linie vil jeg håbe er den eneste relevante:
$handle = opendir('.');

hvis du ændrer '.' til et andet dir bør den læse i det dir.
$handle = opendir('images/');

eftersom du næppe har lyst til at have flere filer af slideshowet liggende kan du rette den til
$handle = opendir($look_in_dir);

så skal du bare sætte $look_in_dir hver gang inden du includer den fil



Indlæg senest redigeret d. 08.03.2008 10:06 af Bruger #5620
Fantastisk:)
det ville sige at jeg kan fremkald img src fra databasen nu??

Kunne dette script også gemmes som en external script, måske hvor man ku brug include() ellers skal det være på hver side?



som jeg sagde så længe du satte $look_in_dir før du includede det script du viste burde det virke .



t