Jump to content


Photo

Array of images in folder


  • Please log in to reply
8 replies to this topic

#1 karl19

karl19
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 May 2006 - 12:33 PM

Hi there,

I'm sorry for these two novice questions, but I really have searched for hours to solve this myself, but to no avail! Hopefully someone has a moment to post a few guidelines to what I presume is a very simple PHP request.

1. Creating a thumbnail gallery from all images in a folder.
2. Giving the thumbnails A HREF links - and making them incremental.

I'm using a nifty little PHP image gallery [a href=\"http://www.mooshow.eatpixels.com/\" target=\"_blank\"](mooShow)[/a] to display a couple of images. There is currently no built-in thumbnail capacity with this script, so I thought I'd simply use PHP to gather the thumbnails from a separate folder. The main images can be hot-linked to by typing in:

<a href="#" onclick="mooShows['myShow'].jumptoImage(4);"/a>

So I thought, great, I'll get all additional thumbnail images with PHP, then add the A HREF link to each thumb, incrementally increasing the value by +1 for every image (jumptoImage(X) above). But alas, I can do neither 1 nor 2!

Happy for any help anyone can give. I'd like to stick with using the image gallery above, but adding the thumbnail feature.

Thanks! Karl

#2 eves

eves
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 May 2006 - 01:22 PM

[!--quoteo(post=376014:date=May 22 2006, 08:33 PM:name=karl19)--][div class=\'quotetop\']QUOTE(karl19 @ May 22 2006, 08:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<a href="#" onclick="mooShows['myShow'].jumptoImage(4);"/a>
[/quote]

couldn't really understand the code you provided but here's a shot of what I think your trying to do
$limit = 10; //total number of images
for($ctr=0;$ctr<$limit;$ctr++)
{
   echo "<a href='#' onclick='jumptoImage($ctr,'".mooShows['myShow']."');'><img src='".$image[$ctr]."' height=100 width=100></a><br>";
}

the jumptoImage() javascript function take 2 parameters, first a counter that will serve as an indentifier for the image and second, the name of the page that will be opened.
I'm just assuming that you would be opening mooShows['myShow'] in a new page or a pop up









#3 karl19

karl19
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 May 2006 - 02:42 PM

Thanks Eves for reading the post!

Sorry if I explained the problem poorly. What I need to do, is first to get a number of images out of a folder, then add links to them.

Ie I have a list of 10 thumbnails in a folder on the server and I want to show them on my portfolio.php page. Apart from adding them to the page, I also want to give them individual and unique links - a href="#1", a href="#2" and so on.

This is the main setup which I'm struggling to solve. I really am a novice with PHP, but presume this is fairly minor surgery?

The code provided above was how the image gallery coder suggested linking directly to the images in the main window. I'm not sure it's the best way, but it works. It's the code I need to use for the links - all constant apart from one variable which would increase +1 with each link.

Hope that explains it better!

Thanks, Karl

[[a href=\"http://www.mooshow.eatpixels.com/example1.php\" target=\"_blank\"]Example gallery[/a]]

#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 22 May 2006 - 11:03 PM

Here's a little number I've been cobbling together. It may be of some help.

Unfortunately, there are some pieces of the code that this forum does not like, so
(1) I have only displayed the initial part of the script that gives a general overview;
and (2) have zipped the script for download here.

[a href=\"http://nstoia.com/phpstuff/list_dir_files.zip\" target=\"_blank\"]http://nstoia.com/phpstuff/list_dir_files.zip[/a]

#########################################
#
# list_dir_files.php
#
#    This is a compilation and modification of 
#    several scripts, snippets, tutorials and
#    examples from the manual
#
#    Major credit goes to 
#    phpDIRList 2.0 - (c)2005 
#    Ulrich S. Kapp :: 
#    Systemberatung :: web-programmierung
#
#    The script reads through a given folder
#    and displays the files contained therein
#
#    There are six variables you may alter
#
#    1.    $allowed_ext - this array is used to set which
#        type of file will be listed
#
#    2.    $directory - this is used to set which directory
#        will be searched/listed
#
#    3.    $do_link - TRUE means display the file
#        name as a link to the file; FALSE means
#        do NOT make the name a link
#
#    4.    $sort_what - this determines what the
#        data will be sorted upon: 0 is by name;
#        1 is by size; 2 is by date last modified
#
#    5.    $sort_how - describes how to sort; 
#        0 means to sort ASCENDING 
#        (oldest to newest, smallest to largest, Z to A); 
#        while 1 means to sort DESCENDING
#        (newest to oldest, largest to smallest, A to Z)
#
#    6.    $limit_ext - controls whether to list all files in
#        the folder or just certain ones. FALSE means all;
#        TRUE means limit according to the values in the
#        $allowed_ext array
#
##################################################


#####################################################
#    These are the six variables
#####################################################


$allowed_ext = array(".gif", ".png", ".jpg", ".jpeg");
$directory = dir("./");
$do_link = TRUE;
$sort_what = 0;
$sort_how = 0;
$limit_ext = TRUE;



Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#5 karl19

karl19
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 May 2006 - 08:25 AM

Hi Lite,

Many thanks for the code! I pasted it into my page and it's now showing a list of the images in the folder I specified.. but how could I get it to actually show the images themselves rather than a list of them? I'd like a graphic display of the actual thumbs in the specific folder, rather than a list.

Also, how would I re-write links from what it is now:

<A HREF="' . $new_array[$i][0] . '">' . $new_array[$i][0] . '</A>

To something like this:

<a href="#" onclick="mooShows['myShow'].jumptoImage(1);"/a>

Where the number in brackets (1) is increased by +1 for every images (1,2,3 and so on). I tried a few different things, but I seem to get the syntax wrong all the time. Perhaps there are a few snippets that can be changed in the code provided?

I also get a list of error messages for each image:

Warning: stat(): Stat failed for 01.jpg (errno=2 - No such file or directory) in [LINK TO FILE] on line 195

Not really sure what this means!

Well, if you have some ideas about the above, I'd obviously be delighted! Bit of a struggle trying to get my head stuck into PHP..

Many thanks, Karl

Ps. How come the forum doesn't like part of the script, btw?

#6 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 23 May 2006 - 12:31 PM

Ok...

Replace the last part of the script with this (it is set to display the images as clickable links and includes the onclick you wanted to use. You may have to 'adjust' your onclick).

I set it so it displays four images in a row (providing they fit on your screen). Obviously, you can easily modify this to display however you want.


###############################################################
#    We display the infomation here
###############################################################

$i2 = count($new_array);
$i = 0;
$new_row=1;
for ($i=0;$i<$i2;$i++) {
    ?>
    <a href="#" onclick="mooShows['myShow'].jumptoImage(
    <?PHP echo $i+1;
    ?>
    );"><IMG SRC= "
    <?PHP echo $directory . $new_array[$i][0];
    ?>
    "></a>
    <?PHP
    if($new_row == 4) {
        echo "<br>";
        $new_row=1;
    }else{
        $new_row = $new_row + 1;
    }
}


As to the 'forum' not liking certain parts; there appears to be a 'bug' that does not allow the displaying of code that contains file read/write operations. Not sure if they have a fix for it yet.

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#7 karl19

karl19
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 May 2006 - 08:28 PM

Hi Lite,

Many thanks again for replying to the post! Sorry it's taken a while to reply, I was away most of last week.

I tried the code you pasted, couldn't get it to work though - it doesn't seem to include any thumbnails on the page? I deleted the previous code from "We display the infomation here" to the end, apart from the closing ?> tag, and pasted in what you sent. All I get is the same error message as before and no thumbnails:

Warning: stat(): Stat failed for 01.jpg (errno=2 - No such file or directory) in [LINK TO FILE] on line 196

Line 196 is this:

$temp_info = stat($file);

Apologies for asking for more info - if it was a matter of the links not working, I'd probably be able to work it out, but I can't seem to figure out why the thumbs are not being imported.

Thanks! Karl

#8 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 31 May 2006 - 08:28 PM

Been jammed up the last few days; however, it did give me some time to redo the script.

Take a look here:

[a href=\"http://www.nstoia.com/mygallery/\" target=\"_blank\"]http://www.nstoia.com/mygallery/[/a]


Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#9 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 06 June 2006 - 06:21 PM

hi,

i came across this script whilst i was searching the internet as i was looking for something that did a similar job.

the script is perfect for what i was looking for, except i have a lot of images to be shown, so i was wondering if there was any way that i could script it s that it only displays a certain number of images per page? i have had a look but i cannot seem to work it out, i am still a novice.

any help on this would be great, thanks very much




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users