PHP image slideshow auto
A solid implementation of an image slideshow gallery. Fully automated, no setup needed.
Usage
For a quick setup:
1. Create a folder for the slideshow images.
2. Drop images for the slideshow in the folder.
3. Grab the code, paste it in a file and call it "index.php"
4. Upload this file to a directory that will be the gallery (http://www.site.com/slideshow/)
5. Change lines 6 and 8 to correspond to your setup.
6. Run it (use URL from step 4)


Comments
Hi I am facing problem with the code
am using wamp server
it shows me following code over the page
and this prob arises pleaseinit()) != '') { header('HTTP/1.1 500 Internal Server Error'); echo $err; exit(); } // get image files from directory $ss->get_images(); // set variables, done. list($curr, $caption, $first, $prev, $next, $last) = $ss->run(); /* slideshow class, can be used stand-alone */ class slideshow { private $files_arr = NULL; private $err = NULL; public function __construct(&$err) { $this->files_arr = array(); $this->err = $err; } public function init() { // run actions only if img array session var is empty // check if image directory exists if (!$this->dir_exists()) { return 'Error retrieving images, missing directory'; } return ''; } public function get_images() { // run actions only if img array session var is empty if (isset($_SESSION['imgarr'])) { $this->files_arr = $_SESSION['imgarr']; } else { if ($dh = opendir(IMGDIR)) { while (false !== ($file = readdir($dh))) { if (preg_match('/^.*\.(jpg|jpeg|gif|png)$/i', $file)) { $this->files_arr[] = $file; } } closedir($dh); } $_SESSION['imgarr'] = $this->files_arr; } } public function run() { $curr = 1; $last = count($this->files_arr); if (isset($_GET['img'])) { if (preg_match('/^[0-9]+$/', $_GET['img'])) $curr = (int) $_GET['img']; if ($curr $last) $curr = 1; } if ($curr = $last) { $prev = $last - 1; $next = $last; } else { $prev = $curr - 1; $next = $curr + 1; } // line below sets the caption name... $caption = str_replace('-', ' ', $this->files_arr[$curr - 1]); $caption = str_replace('_', ' ', $caption); $caption = preg_replace('/\.(jpe?g|gif|png)$/i', '', $caption); $caption = ucfirst($caption); return array($this->files_arr[$curr - 1], $caption, 1, $prev, $next, $last); } private function dir_exists() { return file_exists(IMGDIR); } } ?>
followed by an empty picture reference (question mark) and the First | Previous Next | Last anchors
please help
Reply on zedkazi@gmail.com
hello ,my name is david noori your scripts is very good but i need demo of your script.why you use not demo?
mydavid66@yahoo.com
i wate for your answer.thanks.by
not bad
Thanks, very useful!
What to write on line 8, if this php file and images are in the same folder?
good of u thanks for sharing
This is not an automated script dont user this instead of there are so manu available based on javascript
Nikhil Patel.
To find the absolute path:
<?php echo $_SERVER['DOCUMENT_ROOT']; ?>
1. Copy and paste the above code in a blank page
2. Save it as absolutepath.php
3. Upload it via FTP to the location where you intend to install your images for the slideshow
4. Open your favorite browser and enter the URL to point to this file:
- Example: http://www.your-site.com/absolutepath.php
5. That's it, you should have your absolute path displayed in the screen.
Found these instruction on: http://forum.mamboserver.com/showthread.php?t=80307
This code exposed a weird problem under Snow Leopard:\
If there's no /etc/php.ini, this code works fine. If there is, the PHP code prints out at the top of the page, beginning with "init()) != '') { header('HTTP/1.1 500 Internal Server Error'); ..." followed by an empty picture reference (question mark) and the First | Previous Next | Last anchors.
This prevents this nice little piece of code from working on properly configured commercial hosts. I would REALLY like to use it, but I don't know nearly enough about PHP admin/setup to solve this problem for myself.
Anyone having a solution, please email me at tomdeboni@comcast.net.
Thanks!
it won't work automatically....
Sorry i'm not Php programmer. Can nobody tell me in line 6 & 8 and example for me.
useful my site thank...
This blows to be honest....
Steve, I can't get this to load the image directory. Tried checking root and www settings on line 6 & 8, still no go? Help!
Thx, works fine only one problem. When U klick next the page uppdates, so itt will jump back to the top of the page. How can i fix?
I like this very much. I am a php programmer and Thank you very much for this code.
You will have to use Javascript setTimeout() for this.
It will be something along these lines:
Nice job.
Any chance to have the images rotate automatically in an given interval?
Thanks for your reply,
Chris.
Good !!!! Thanks a lot
Reading for the text widget at the Wordpress.com site, I believe you
can add an iframe with the URL as src. Then the gallery will be displayed.
Just guessing, I am not a Wordpress user.
Can anybody help explain how you would do #6 in wordpress? How would you access this php from a text widget in your sidebar?
Here is a working page with the script:
http://bmwhandlebarrisers.com/gallery/idigallery.php
A demonstration of what the end result will look like would be nice :)
Can I add this to my own existing site?
Thanks a lot!
Not bad