[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 10-31-2006, 03:04 PM   #1 (permalink)
New Member
 
Join Date: Oct 2006
Posts: 12
0.00 NP$ (Donate)

radiocricket is an unknown quantity at this point


CLOSED- PROBLEM SOLVED- Need PHP Help with Rotating Random Images

This is driving me crazy, I can't get this PHP to work. I purchased a license from www.dyn-web.com to use this PHP and javascript and even they can't see what I'm doing wrong. Here it goes- these are the instructions straight off www.dyn-web.com:



Place script tags for the required JavaScript files in the head of the document:

<script src="js/dw_rotator.js" type="text/javascript"></script>
<script src="js/dw_random.js" type="text/javascript"></script>


A few PHP variables and functions need to be placed or included early in the document:

<?php
$path_to_images = "images/"; // path to your images
$num_to_rotate = 12; // number or "ALL" (to rotate all images in directory)

// returns string to echo into JavaScript images array
function getJSRandomized($path, $list, $num) {
$str = '"';
mt_srand( (double)microtime() * 1000000 );
shuffle($list);
if ( $num == "ALL" ) $num = count($list);
for ($i=0; $i<$num; $i++) {
$str .= $path . $list[$i] . '", "';
}
// remove last comma and space
$str = substr($str, 0, -3);
return $str;
}

function getImagesList($path) {
$ctr = 0;
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// add checks for other image file types here, if you like
if ( preg_match("/(\.gif|\.jpg)$/", $img_file) ) {
$images[$ctr] = $img_file;
$ctr++;
}
}
closedir($img_dir);
return $images;
} else {
return false;
}
}
?>


Include a call to the dw_Rotator.start function in the body onload event handler attribute:

<body onload="dw_Rotator.start()">

Place the following mixture of JavaScript and PHP tag segments where the image rotation is to take place in your document:

<?php if ( $image_list = getImagesList($path_to_images) ) : ?>

<script type="text/javascript">
/************************************************** ***********************
This code is from Dynamic Web Coding at dyn-web.com
Copyright 2001-5 by Sharon Paine
See Terms of Use at dyn-web.com/bus/terms.html
regarding conditions under which you may use this code.
This notice must be retained in the code as is!

See full source code at dyn-web.com/scripts/rotate-rand/
************************************************** ***********************/
var imgList = [
<?php echo getJSRandomized($path_to_images, $image_list, $num_to_rotate); ?>
];
var rotator1 = new dw_RandRotator(4000); // rotation speed
// images array, width and height of images, transition filter (boolean)
rotator1.setUpImage(imgList, null, null, false);
</script>

<?php else : ?>
<!-- image to display if directory listing fails -->
<img src="images/smile.gif" width="88" height="88" alt="">

<script type="text/javascript">dw_Rotator.start = function() {};</script>

<?php endif; ?>


I've changed the names to the paths I'm using but still it doesn't work. All I get is the image I want displayed if the directory fails. So I'm assuming my directory is failing. I don't have any .php saved so maybe that's the problem? I have no idea how PHP works, I've learned more code than I ever thought I would but obviously not enough. Dyn-Web did give me this suggestion:

"The most common problem with the PHP version involves the path to the images. If the images folder is in a directory under the document, usually it works with no problem. Otherwise you could include $_SERVER['DOCUMENT_ROOT'] in the path and this generally solves the problem."


I tried this but can't be sure I implemented it correctly. I would really like to pull images out of a directory. I will have hundreds to rotate through and I don't want to have to manually type in each image name into each webpage. I'd much rather have the PHP and just save images into a directory and never worry about updating each page every time I add an image. I love the javascript, it is exactly what I was looking for so I don't want to give up on it.

I am designing with Dreamweaver so maybe that's causing the problem? In one line of the code is says to delete the last comma and space which I have done on my page, it hasn't made a difference if I do it or not. Please help and forgive me if I'm asking anything ignorant.

-Janice

Last edited by radiocricket; 11-02-2006 at 04:50 AM. Reason: Problem Solved
radiocricket is offline  
Old 11-02-2006, 12:02 AM   #2 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


Heh, i know it sounds to simple but have you made sure that you've chmod'd the image directory to something like 777?
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Old 11-02-2006, 04:29 AM   #3 (permalink)
New Member
 
Join Date: Oct 2006
Posts: 12
0.00 NP$ (Donate)

radiocricket is an unknown quantity at this point


I don't know what chmod'd stands for!

Someone has helped me with the problem by writing a different script. Thanks for the help!

-Janice
radiocricket is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 05:32 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85