Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: Help with code to create an array from contents of folder

  1. #11
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Okay, here's the link to the page I'm trying to get working: http://ohiobuttons.org/test/NewFadinSlideShow_1.html

    Beverley. I tried putting it up as a .php page, but it displays a blank page. Also, I tried every combination I could think of using the examples you gave me. Nothing worked. I still haven't been able to get a hold of my server's tech support people. I'll keep trying.

  2. #12
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    At this stage I think you should go back to basics and confirm that the PHP is working for you. I've tested this code here and it works fine for me (in a page called "test.php");
    Code:
    <?php
         
    
    function imageSlideArray($dir, $path) {
    
    //$dir = '/home/www/mywebsite.com/images/';
    //$path = 'Graphics/ShowPics/';
    
    $patterns = '/\.(jpg|jpeg|png)$/'; // only these file types
    if($hd = opendir($dir)){               
    	while(false !== ($fname = readdir($hd))){                       
    		if(preg_match('/^\.{1,2}$/',$fname)) continue; // exclude current directory, parent directory 
    		if(!preg_match($patterns,$fname)) continue; // exclude file types not in $patterns     
     		$files_array[] = $fname;
    		}
    	}
    sort($files_array); // sort files a-z 
    for ($i = 0; $i < count($files_array); $i++) { 
        $comma = ($i != count($files_array) - 1) ? ',' : ''; // if next item exists in array set $comma as ',' else '' (nothing)
        echo "[\"$path$files_array[$i]\"]$comma<br/>"; 
    }
    closedir($hd); 
    
    }
    ?>
    
    
    <?php imageSlideArray('/home/www/mywebsite.com/images/', 'Graphics/ShowPics/');?>
    Prints out this;
    Code:
    ["Graphics/ShowPics/about.jpg"],
    ["Graphics/ShowPics/bookmark.jpg"],
    ["Graphics/ShowPics/calendar.jpg"],
    ["Graphics/ShowPics/cross.jpg"],
    ["Graphics/ShowPics/demo.jpg"],
    ["Graphics/ShowPics/display.jpg"],
    ["Graphics/ShowPics/exclamation.jpg"],
    ["Graphics/ShowPics/extras.jpg"]
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It's unlikely that any PHP code on an HTML page will execute and the PHP code on that HTML page looks like it wouldn't do anything anyway. However, because not even build_array.php appears to work as advertised, unless that's been changed, it looks like PHP is not available on the server. But it might be something(s) else (permissions, bad coding, etc.) are you certain that PHP is available and turned on for that account? If so, does it have directory reading permission? Why is the index PHP file 'unavailable'? I can see it right there in folder view, that almost must be a permission issue at least for that file.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #14
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Beverly, we cross posted. Your code works here also. And I agree there is some doubt PHP is available. In your code I would add case insensitivity to the pattern:

    Code:
    $patterns = '/\.(jpg|jpeg|png)$/i'; // only these file type
    and possibly other image types (bmp, gif).

    Oh. and you cannot use <br> in javascript like that:

    Code:
    echo "[\"$path$files_array[$i]\"]$comma<br/>";
    Use a line break:

    Code:
    echo "[\"$path$files_array[$i]\"]$comma\n";
    It won't look so pretty on the page, but will look fine in source view, which is what counts in javascript.
    Last edited by jscheuer1; 04-16-2014 at 02:47 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #15
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Will do and thanks for the case insensitivity tip John
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  6. #16
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Okay, guys. Now I'm thoroughly confused.

    John - PHP is enabled on the server, I use PHP routines on other pages and they work fine. I'm not sure where you found index.php, it's not a file that I use in this application.

    Beverley - I haven't tried the code that you listed. I will, and let you know.

    Nothing I've read explains why, if I define it as an .html page, the page displays properly, but the slideshow doesn't work. However, if I define it as a .php page, nothing works.

    As to the coding, I'm simply copying the code that Beverley sent me. I think Beverley is right in that it has something to do with the addressing. I'm still trying to work on that.

  7. #17
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Okay, guys. I finally got a hold of the server tech support. Beverley, you were right. The server path was VERY different. I've modified the code to use the new server paths and it works ... sort of. What happens now is that the webpage displays, but it shows the list of files in ShopPics instead of sending the array to the fadeslideshow script. Here's what the code looks like now, so we're all on the same page, so to speak:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    
    <?php include('/hsphere/local/home/bswebmas/ohiobuttons.org/test/Script_Files/build_array.php');?>
    
    <script type="text/javascript" src="Script_Files/fadeslideshow.js">
    /***********************************************
    * Ultimate Fade In Slideshow v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
    ***********************************************/
    
    </script>
    
    <script>
    var ShowPics=new fadeSlideShow({
    	wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    	dimensions: [400, 300], //width/height of gallery in pixels. Should reflect dimensions of largest image
    	imagearray: [
    </script>
    <?php imageSlideArray('/hsphere/local/home/bswebmas/ohiobuttons.org/test/Graphics/ShowPics/', '/test/Graphics/ShowPics/');?>
    <script>
    	],
    	displaymode: {type:'auto', pause:2000, cycles:1, wraparound:false},
    	persist: false, //remember last viewed slide and recall within same session?
    	fadeduration: 500, //transition duration (milliseconds)
    	descreveal: "none",
    	togglerid: ""
    })
    </script>
    
    </head>
    
    <body bgcolor="#FEF4E4">
    <center>
    <table cellspacing=1 border=0 width=100%>
    <tr>
    <td colspan=3 valign="top" align="center"><font size="4" color="Navy"><b>The Buckeye State Button Society<br>presents</b></td></tr>
    <tr>
    <td align="center" valign="middle"><p><font size="6" color="Green" face="Arial"><center>Spring Show 2014</font>
    <p><font size=4 color="Navy"><b>April 9-10, 2015</b></font></td>
    </tr><tr>
    <td align="center">
    <table border=0>
    <td align="center" valign="top">
    
    <div id="fadeshow1"></div>
    
    </td>
    </tr></table>
    </tr></table>
    </center>
    </body>
    </html>
    Here's what the page display looks like: Click image for larger version. 

Name:	Image2.jpg 
Views:	107 
Size:	94.4 KB 
ID:	5429

    I feel like we're really close to getting this solved. I really want to thank both of you for all your help. Any thoughts on the next step would be greatly appreciated.

  8. #18
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    If you have a look at my previous posts, you'll see that the script tags do not close and then open again around the php function call.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  9. #19
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Also, in the function that makes the array you have to change <br> to \n (see my previous post)
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #20
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Beverley - I didn't think that they should go there, but if I take out the tags, I just get the html code executed. I don't even get the file list.

    John - Thanks for the reminder. With everything else, I just overlooked that.

    I've changed the code (taken out the script tags and replace the <br> tag).

Similar Threads

  1. Script to show folder contents
    By dwarfer in forum Looking for such a script or service
    Replies: 7
    Last Post: 07-14-2012, 04:20 AM
  2. can lightbox read the contents of a folder
    By mtokoly in forum Dynamic Drive scripts help
    Replies: 11
    Last Post: 07-13-2009, 08:17 PM
  3. Create new folder and .TXT file
    By Spinethetic in forum PHP
    Replies: 4
    Last Post: 03-24-2009, 02:03 AM
  4. Building a dynamic array from folder contents
    By Jim Weinberg in forum JavaScript
    Replies: 20
    Last Post: 05-15-2008, 03:34 PM
  5. php folder array
    By insanemonkey in forum PHP
    Replies: 0
    Last Post: 11-06-2007, 05:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •