Trying to print image list in server directory.

The script that I’m trying to run is straight forward, at least think it’s straight forward. I got the script from this site - http://www.brightcherry.co.uk/scribbles/php-list-all-files-in-a-directory/ ,(sorry I can’t post links yet), when searching on how to list file names from a server directory. I found quite a few places on the subject and all seemed a bit overly complicated compared to the one in the link above. the script is as follows :

[php]

//path to directory to scan
$directory = “EXAMPLE_IMAGES_PATH”;

//get all image files with a .jpg extension.
$images = glob($directory . “*.jpg”);

//print each file name
foreach($images as $image)
{
echo $image;
}
[/php]

I’ve attempted other variations of the echo like this :

[php]
echo “”;
echo “”;
echo “<img src=/”/";echo $image;echo “/”//>"
echo “”;
[/php]

The final html output for each should look like this :

<img src="/path/to/image/*.jpg"/>

I’m not getting anything back. How can I make this work for me. I’m also going to be extending it to be a little more complicated. Something like this :

[php]
echo :$page->pagename";echo “/”; //This would be echoed after EXAMPLE_IMAGES_PATH
[/php]

The final html output would then be :

<img src="/path/to/image/pagename/*.jpg"/>

Any help on how to accomplish this in any variation would be of great help and great learning experience as well.

Something like this would be what I’m tryng to acomplish :

[php]
$images = glob(EXAMPLE_IMAGES_PATH . ($page->pagename) “/” “*.jpg” );
foreach($images as $image)
{
echo $image;
}
[/php]

I’m now getting the images to display. The help that I need is to get ($page->pagename) to show after EXAMPLE_IMAGES_PATH with / following it, followed by the image file as to get the final result of :

<img src="/path/to/image/pagename/*.jpg"/>

Right now I’m getting this :

<img src="/path/to/image/*.jpg"/>

Within the pages that these will be shown I’m able to echo pagename anywhere like this:

[php]

<?php echo $page->pagename ?>

[/php]

Again much appreciated on any assistance.

are you using a paging script

to get the pagename
or how you getting the pagename

@cabalsdemon, I’m not sure exactly what you mean by paging script but this will be displayed within the page where the data for page exist like this : page->pagename (the example I’m using) is really something similar to something like Article->Articlename from the database. I’m sorry if this is causing any confusion at all.

A little more to explain myself. Within (pagename) there is no pagination only the option of home, contact, or to view list of more pages(list pagename’s). Again sorry if this seems unclear.

well to change the url you can put str_replace
http://php.net/manual/en/function.str-replace.php
to make it look like a pagename and make pagename come from a database
unless your pagename wil be a folder name that is anotheer album ?
but other then that
i have to get to work so a little help will be when i get home :slight_smile:

@cabalsdemon - I got it to work! :slight_smile: I now understand what you meant though. This has been a great learning experience as far ( glob() ) goes. I’m soon getting to where I want to get in php. The help here on this site has been so awesome, I just love it.

can you post how you did it for another person might be trying that

Here’s how I got it to work.

[php]
$images = glob(EXAMPLE_IMAGES_PATH . $results[‘page’]->pagename ."/" . “{.jpg,.jpeg,.JPG,.JPEG}”,GLOB_BRACE);
[/php]

I had forgot to add the results for:

[php]
$results = array();
$results[‘pages’] = $data[‘results’];
[/php]

ok thanks we will work on your other posts

[php][/php]

?

[php]
$file_type = strtolower( end (explode (’.’, $file)));
if($file !== ‘.’ && $file !== ‘…’ && in_array($file_type, $file_display)== true)
{
echo ‘

  • ', $file,'
  • ’;

    [/php]

    Sponsor our Newsletter | Privacy Policy | Terms of Service