473,778 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need help with my gallery

Hi everybody
I have yet another problem, actually two but lets start with this
one :-)
Im making a very simple gallery or at least I think its simple.
I have already made a upload script that uploads and resizes the image
and also creates a thumbnail.
So now I have my folder "images/galleri/" and "images/galleri/thumbs".
Now its time to dynamically display the images on a page.
I have set the $filename variable to display the thumbnails as you can
see below but how do I set the $filename_stor to link to the large
image. Perhaps im "attacking" this problem all wrong? I have tried to
nest another foreach in the first but that just messed everything up.

<?php
foreach (glob('images/galleri/thumbs/*.jpg') as $filename ) {
echo '<td><a href="'.$filena me_stor.'" rel="milkbox[]" <img
src="'.$filenam e.'" </a>'."&nbsp;&nbs p;</td>";
}
?>
The 2nd problem is that I want the images in a table that is no more
than 6 colums wide and N number of rows. Im thinking that I proberly
need to use an array!?

Any suggestions or solutions are very welcome
I hope you can help me.

-Effix
Aug 9 '08 #1
13 1340
On 9 Aug., 23:26, Effix <Morteneist...@ gmail.comwrote:
Hi everybody
I have yet another problem, actually two but lets start with this
one :-)
Im making a very simple gallery or at least I think its simple.
I have already made a upload script that uploads and resizes the image
and also creates a thumbnail.
So now I have my folder "images/galleri/" and "images/galleri/thumbs".
Now its time to dynamically display the images on a page.
I have set the $filename variable to display the thumbnails as you can
see below but how do I set the $filename_stor to link to the large
image. Perhaps im "attacking" this problem all wrong? I have tried to
nest another foreach in the first but that just messed everything up.

<?php
foreach (glob('images/galleri/thumbs/*.jpg') as $filename ) {
* * echo '<td><a href="'.$filena me_stor.'" rel="milkbox[]" <img
src="'.$filenam e.'" </a>'."&nbsp;&nbs p;</td>";}

?>

The 2nd problem is that I want the images in a table that is no more
than 6 colums wide and N number of rows. Im thinking that I proberly
need to use an array!?

Any suggestions or solutions are very welcome
I hope you can help me.

-Effix
I forgot to mention that both the thumbnail and the large image have
the same filename but different path.
Aug 10 '08 #2
Message-ID:
<f8************ *************** *******@m44g200 0hsc.googlegrou ps.comfrom
Effix contained the following:
>Im making a very simple gallery or at least I think its simple.
I have already made a upload script that uploads and resizes the image
and also creates a thumbnail.
So now I have my folder "images/galleri/" and "images/galleri/thumbs".
Now its time to dynamically display the images on a page.
I have set the $filename variable to display the thumbnails as you can
see below but how do I set the $filename_stor to link to the large
image. Perhaps im "attacking" this problem all wrong? I have tried to
nest another foreach in the first but that just messed everything up.
In my gallery script I have used a naming convention for the images.
Original images are in one folder with their original names Display
images are in another folder and are prefixed like so b_$filename
Similarly, thumbnails are names s_$filename So if I get the filenames
of the main images I automatically know the filenames of the display and
thumbnail images.

I've used CSS to display the images dynamically so don't have the table
problem (www.slipperyhill.co.uk/gallery ). If you do want to use a
table you need to check each time the loop returns to see if you need to
insert a </tr You could check the modulus of a counter to do this.
Assuming your filename are in $filename_array and combining the two
ideas, you might have something like this:-

//set up variables
$thumbs_dir='th umbs/';
$display_dir='d isplay/';

$table="<table id='thumbnails' >\n<tr>\n";
$count=1;
//loop through filenames
foreach($filena me_array as $filename){
$table.=($count %6==0)?"</tr>\n<tr>\n":"" ;
$table.="<td><a href='".$displa y_dir."b_".$fil ename."' ><img
src='".$thumbs_ dir."s_".$filen ame."'></a></td>\n";
$count++;
}
//finish off table row
while($count%6! =0){
$table.="<td>&n bsp;</td>\n";
$count++;
}
$table.="<tr>\n </table>";
//echo table to screen;
echo $table;

Untested.


--
Geoff Berrow 011000100110110 0010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011
http://slipperyhill.co.uk
Aug 10 '08 #3
Message-ID:
<ca************ *************** *******@m44g200 0hsc.googlegrou ps.comfrom
Effix contained the following:
>
I forgot to mention that both the thumbnail and the large image have
the same filename but different path.
You can easily modify the solution I just posted by removing the
prefixes.

--
Geoff Berrow 011000100110110 0010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011
http://slipperyhill.co.uk
Aug 10 '08 #4
On 10 Aug., 12:44, Geoff Berrow <blthe...@ckdog .co.ukwrote:
Message-ID:
<ca397970-3e5a-4c66-8cb2-e3e19979c...@m4 4g2000hsc.googl egroups.comfrom
Effix contained the following:
I forgot to mention that both the thumbnail and the large image have
the same filename but different path.

You can easily modify the solution I just posted by removing the
prefixes.

--
Geoff Berrow *01100010011011 00010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011htt p://slipperyhill.co .uk
Thank you for yor solution Geoff. Your right I have my files in an
arrray. I use the glob() function. It seems theres no way to strip the
path from the glob() function so my array contains path and filename.
Is there an alternative to glob which only gives me the filenames?
could scandir() work?
-Effix
Aug 10 '08 #5
Message-ID:
<e4************ *************** *******@k7g2000 hsd.googlegroup s.comfrom
Effix contained the following:
>Thank you for yor solution Geoff. Your right I have my files in an
arrray. I use the glob() function. It seems theres no way to strip the
path from the glob() function so my array contains path and filename.
Is there an alternative to glob which only gives me the filenames?
could scandir() work?
Well presumably you know the path(s). You just need the portion to the
right of the last '/'

strrchr () will give you everything from the last '/' onwards

so

$filename= substr(strrchr ($filepath,"/"), 1)
--
Geoff Berrow 011000100110110 0010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011
http://slipperyhill.co.uk
Aug 10 '08 #6
On 10 Aug., 16:07, Geoff Berrow <blthe...@ckdog .co.ukwrote:
Message-ID:
<e4e3f8fb-8fb9-4599-a975-f942c9214...@k7 g2000hsd.google groups.comfrom
Effix contained the following:
Thank you for yor solution Geoff. Your right I have my files in an
arrray. I use the glob() function. It seems theres no way to strip the
path from the glob() function so my array contains path and filename.
Is there an alternative to glob which only gives me the filenames?
could scandir() work?

Well presumably you know the path(s). *You just need the portion to the
right of the last '/' *

strrchr () will give you everything from the last '/' onwards

so

$filename= substr(strrchr ($filepath,"/"), 1)
--
Geoff Berrow *01100010011011 00010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011htt p://slipperyhill.co .uk
Aah I see I was trying to use trim() to remove the path from the array
but that didnt work :)
Altohug I cant seem to get strrchr to work either, im sorry to be such
a bother. Apparently it strips the path but no filename appears efter
the last /
here is my code so far, not modified much (not yet anyways :) ) from
your original suggestion.

//set up variables
$filename_array = glob('images/galleri/thumbs/*.jpg');
$filepath= 'images/galleri/thumbs/' ;
$thumbs_dir='im ages/galleri/thumbs/';
$display_dir='i mages/galleri/';
$table="<table id='thumbnails' >\n<tr>\n";
$count=1;
//loop through filenames
foreach($filena me_array as $filename){
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
$table.=($count %6==0)?"</tr>\n<tr>\n":"" ;
$table.="<td><a href='".$displa y_dir."".$filen ame."' ><img
src='".$thumbs_ dir."".$filenam e."'></a></td>\n";
$count++;

}
//finish off table row
while($count%6! =0){
$table.="<td>&n bsp;</td>\n";
$count++;

}

$table.="<tr>\n </table>";
//echo table to screen;
echo $table;

?>

This results in a page with a table that look like this
<table id='thumbnails' >
<tr>
<td><a href='images/galleri//' ><img
src='images/galleri/thumbs//'></a></td>
<td><a href='images/galleri//' ><img
src='images/galleri/thumbs//'></a></td>
<td><a href='images/galleri//' ><img
src='images/galleri/thumbs//'></a></td>
<td><a href='images/galleri//' ><img
src='images/galleri/thumbs//'></a></td>
<td><a href='images/galleri//' ><img
src='images/galleri/thumbs//'></a></td>
</tr>
<tr>
<td><a href='images/galleri//' ><img
src='images/galleri/thumbs//'></a></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<tr>
</table>

What am I doing wrong?

-Effix (beginning to get a bit confused :) )
Aug 10 '08 #7
Message-ID:
<b9************ *************** *******@k7g2000 hsd.googlegroup s.comfrom
Effix contained the following:
>Aah I see I was trying to use trim() to remove the path from the array
but that didnt work :)
Altohug I cant seem to get strrchr to work either, im sorry to be such
a bother. Apparently it strips the path but no filename appears efter
the last /
Don't worry about being confused, it probably has a lot to do with me
being lazy and not explaining properly.

Look at this:

foreach($filena me_array as $filename){
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
....

$filepath in this instance was meant to be the output from your array
(with the path bit that you didn't want)
substr() was being used to strip off the leading '/'.

So it should be:-

foreach($filena me_array as $filename){
//strip path so we just have filename
$filename= substr(strrchr ($filename,"/"), 1) ;
....
--
Geoff Berrow 011000100110110 0010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011
http://slipperyhill.co.uk
Aug 10 '08 #8
<comp.lang.ph p>
<Effix>
<Sun, 10 Aug 2008 07:52:42 -0700 (PDT)>
<b9************ *************** *******@k7g2000 hsd.googlegroup s.com>
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
Not really paid much attention to this thread - but shouldnt that be the
following .....

$filename=subst r(strrchr($file path,"/"),1) ;

Or perhaps you could use basename as it does the job in this particular
case .

$filename=basen ame($filepath);
--
www.cannabisaware.co.uk
Aug 10 '08 #9
On 10 Aug., 17:33, Krustov <m...@privacy.n etwrote:
<comp.lang.ph p>
<Effix>
<Sun, 10 Aug 2008 07:52:42 -0700 (PDT)>
<b9058dc3-6a0b-41e3-b779-2496d6acf...@k7 g2000hsd.google groups.com>
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;

Not really paid much attention to this thread - but shouldnt that be the
following .....

$filename=subst r(strrchr($file path,"/"),1) ;

Or perhaps you could use basename as it does the job in this particular
case .

$filename=basen ame($filepath);

--www.cannabisawa re.co.uk
Yeah it should be as you say but that didnt work so I tried to
tinkering with the settings to get any results but still nothing
happens.
-Effix
Aug 10 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2282
by: Captain Ranger McCoy | last post by:
Hello! Suppose I have ten servers at ten ips: x.x.x.1 x.x.x.2 x.x.x.3 x.x.x.4 and so on Each server hosts 100+ photo galleries, all under a single domain name,
1
1795
by: Chris Shipley | last post by:
I am trying to present a list of links on a page (Form) where each link opens a different picture gallery. I have the Form page which contains the links, a Gallery page, and several include files. Each include file displays a different gallery. Clicking on a link submits a value identifying the chosen gallery to the Gallery page. The Gallery page accepts the value from the Form page and uses it to call the appropriate include file. The...
2
2534
by: robert | last post by:
I've made a gallery site for an artist and it works well -- the gallery page has a central large image which is swapped when thumbnail images are clicked. I'm using Dreamweaver's "SwapImage" behavior. The problem is that this fails under certain versions of IE and possibly NN on PCs and Macs -- I haven't gotten my client to send me details of what version he's using (sorry) or any of my 'beta testers' -- but I'm really getting frustrated....
7
3271
by: Eric Lindsay | last post by:
I would like to do a photo gallery with a liquid layout. I wanted to center a caption below each photo (or above each photo). I can do that easily with tables, but then I don't have a liquid layout. Besides, I wanted to try to do it with CSS. I can do centered captions with text-align. This works provided the element containing each photo is floated left. I have found several examples of how to do this. However I didn't want the...
1
2324
by: gescom | last post by:
My goal is to create essentially two galleries on a single page, in which the first gallery determines what the second gallery displays. For instance, the first gallery refers to the contents of the main image folder. The second gallery would be a folder inside the main image folder. Depending on which image is displayed, the first gallery's image would trigger the second gallery's contents. I suppose this is sort of a hierarchal gallery...
1
1261
by: 4wheelinwilly | last post by:
I am somewhat new to PHP, but really like it so far. I have created a database (MySQL) and upload/edit pages enabling the user to upload photos and descriptions. Outputing them in a gallery format is not a problem. What I am struggling with is when there are many photos. I would like to keep the gallery pages to 20 images. If there are 50 images in the database, how would I write a code to continue the gallery on subsequent pages? Keeping...
5
2122
by: dabhand | last post by:
Hi This page http://www.dabhand.co.nz/ayupdev/gallery-riders.html works great in IE but not in Firefox... any help would be appreciated. It refers to an external javascript file which I have included the code to below: The file name is imgriders.js - as referred to in source of the html file above. if (document.images) { image1 = new Image; image2 = new Image; image3 = new Image;
7
1830
by: MZ | last post by:
Hello, I have a webcam connected to the Internet. I can access the current static picture of the camera using an url link. It shows the picture with high resolution 1600x1200. I would like to have a batch program which will do what follows every some amount of time: 1. save the picture automatically on my local computer (which will be always running) 2. lower the resolution of the saved picture
2
2315
anfetienne
by: anfetienne | last post by:
hi, i've got a flash gallery which i've paid for. Im using swf object to import vars to the gallery....the var being imported is a html address to specify the location of files and folders. The problem is that the gallery detects the thumbnails and loads the 1st image but once i click on another image it wont load, i don't know why it it doing this and as it loads the thumbnails which are in the same location it shouldn't have a problem...
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.