Jump to content

Array of images in folder


karl19

Recommended Posts

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:

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

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([b]X[/b]) 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
Link to comment
Share on other sites

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

couldn't really understand the code you provided but here's a shot of what I think your trying to do
[code]
$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>";
}
[/code]

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







Link to comment
Share on other sites

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]]
Link to comment
Share on other sites

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]

[code]
#########################################
#
# 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;

[/code]


Lite...
Link to comment
Share on other sites

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:

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

To something like this:

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

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:

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

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?
Link to comment
Share on other sites

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.


[code]
###############################################################
#    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;
    }
}
[/code]


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...
Link to comment
Share on other sites

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:

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

Line 196 is this:

[code]$temp_info = stat($file);[/code]

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.