Connecting Tech Pros Worldwide Forums | Help | Site Map

I need help with my gallery

Effix
Guest
 
Posts: n/a
#1: Aug 9 '08
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="'.$filename_stor.'" rel="milkbox[]" <img
src="'.$filename.'" </a>'."&nbsp;&nbsp;</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
Effix
Guest
 
Posts: n/a
#2: Aug 10 '08

re: I need help with my gallery


On 9 Aug., 23:26, Effix <Morteneist...@gmail.comwrote:
Quote:
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="'.$filename_stor.'" rel="milkbox[]" <img
src="'.$filename.'" </a>'."&nbsp;&nbsp;</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.
Geoff Berrow
Guest
 
Posts: n/a
#3: Aug 10 '08

re: I need help with my gallery


Message-ID:
<f8364aac-c842-4644-aa66-bfac62c64984@m44g2000hsc.googlegroups.comfrom
Effix contained the following:
Quote:
>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='thumbs/';
$display_dir='display/';

$table="<table id='thumbnails'>\n<tr>\n";
$count=1;
//loop through filenames
foreach($filename_array as $filename){
$table.=($count%6==0)?"</tr>\n<tr>\n":"";
$table.="<td><a href='".$display_dir."b_".$filename."' ><img
src='".$thumbs_dir."s_".$filename."'></a></td>\n";
$count++;
}
//finish off table row
while($count%6!=0){
$table.="<td>&nbsp;</td>\n";
$count++;
}
$table.="<tr>\n</table>";
//echo table to screen;
echo $table;

Untested.




--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Geoff Berrow
Guest
 
Posts: n/a
#4: Aug 10 '08

re: I need help with my gallery


Message-ID:
<ca397970-3e5a-4c66-8cb2-e3e19979ce3e@m44g2000hsc.googlegroups.comfrom
Effix contained the following:
Quote:
>
>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 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Effix
Guest
 
Posts: n/a
#5: Aug 10 '08

re: I need help with my gallery


On 10 Aug., 12:44, Geoff Berrow <blthe...@ckdog.co.ukwrote:
Quote:
Message-ID:
<ca397970-3e5a-4c66-8cb2-e3e19979c...@m44g2000hsc.googlegroups.comfrom
Effix contained the following:
>
>
>
Quote:
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 *0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011http://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
Geoff Berrow
Guest
 
Posts: n/a
#6: Aug 10 '08

re: I need help with my gallery


Message-ID:
<e4e3f8fb-8fb9-4599-a975-f942c92145fd@k7g2000hsd.googlegroups.comfrom
Effix contained the following:
Quote:
>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 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Effix
Guest
 
Posts: n/a
#7: Aug 10 '08

re: I need help with my gallery


On 10 Aug., 16:07, Geoff Berrow <blthe...@ckdog.co.ukwrote:
Quote:
Message-ID:
<e4e3f8fb-8fb9-4599-a975-f942c9214...@k7g2000hsd.googlegroups.comfrom
Effix contained the following:
>
Quote:
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 *0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011http://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='images/galleri/thumbs/';
$display_dir='images/galleri/';


$table="<table id='thumbnails'>\n<tr>\n";
$count=1;
//loop through filenames
foreach($filename_array as $filename){
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
$table.=($count%6==0)?"</tr>\n<tr>\n":"";
$table.="<td><a href='".$display_dir."".$filename."' ><img
src='".$thumbs_dir."".$filename."'></a></td>\n";
$count++;

}
//finish off table row
while($count%6!=0){
$table.="<td>&nbsp;</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 :) )
Geoff Berrow
Guest
 
Posts: n/a
#8: Aug 10 '08

re: I need help with my gallery


Message-ID:
<b9058dc3-6a0b-41e3-b779-2496d6acfb03@k7g2000hsd.googlegroups.comfrom
Effix contained the following:
Quote:
>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($filename_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($filename_array as $filename){
//strip path so we just have filename
$filename= substr(strrchr ($filename,"/"), 1) ;
....


--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Krustov
Guest
 
Posts: n/a
#9: Aug 10 '08

re: I need help with my gallery


<comp.lang.php>
<Effix>
<Sun, 10 Aug 2008 07:52:42 -0700 (PDT)>
<b9058dc3-6a0b-41e3-b779-2496d6acfb03@k7g2000hsd.googlegroups.com>
Quote:
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
>
Not really paid much attention to this thread - but shouldnt that be the
following .....

$filename=substr(strrchr($filepath,"/"),1) ;

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

$filename=basename($filepath);


--
www.cannabisaware.co.uk
Effix
Guest
 
Posts: n/a
#10: Aug 10 '08

re: I need help with my gallery


On 10 Aug., 17:33, Krustov <m...@privacy.netwrote:
Quote:
<comp.lang.php>
<Effix>
<Sun, 10 Aug 2008 07:52:42 -0700 (PDT)>
<b9058dc3-6a0b-41e3-b779-2496d6acf...@k7g2000hsd.googlegroups.com>
>
Quote:
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
>
Not really paid much attention to this thread - but shouldnt that be the
following .....
>
$filename=substr(strrchr($filepath,"/"),1) ;
>
Or perhaps you could use basename as it does the job in this particular
case .
>
$filename=basename($filepath);
>
--www.cannabisaware.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
Geoff Berrow
Guest
 
Posts: n/a
#11: Aug 11 '08

re: I need help with my gallery


Message-ID: <MPG.23091aa334eb4ff98b848@news.newsreader.comfr om Krustov
contained the following:
Quote:
>
>Not really paid much attention to this thread - but shouldnt that be the
>following .....
>
>$filename=substr(strrchr($filepath,"/"),1) ;
No, in this instance it's $filename=substr(strrchr($filename,"/"),1) ;
Quote:
>
>Or perhaps you could use basename as it does the job in this particular
>case .
Yes, I'd forgotten about that function.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Effix
Guest
 
Posts: n/a
#12: Aug 11 '08

re: I need help with my gallery


On 10 Aug., 17:21, Geoff Berrow <blthe...@ckdog.co.ukwrote:
Quote:
Message-ID:
<b9058dc3-6a0b-41e3-b779-2496d6acf...@k7g2000hsd.googlegroups.comfrom
Effix contained the following:
>
Quote:
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($filename_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($filename_array as $filename){
//strip path so we just have filename
$filename= substr(strrchr ($filename,"/"), 1) ;
...
>
--
Geoff Berrow *0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011http://slipperyhill.co.uk
Aaah I see now it makes a lot more sense :) I cant belive I didnt
figure that one out myself ofcourse its the filename that needs to be
stripped and not the path as I did.
Thank your very much for your help Geoff! :)
Effix
Guest
 
Posts: n/a
#13: Aug 11 '08

re: I need help with my gallery


On 11 Aug., 10:35, Effix <Morteneist...@gmail.comwrote:
Quote:
On 10 Aug., 17:21, Geoff Berrow <blthe...@ckdog.co.ukwrote:
>
>
>
>
>
Quote:
Message-ID:
<b9058dc3-6a0b-41e3-b779-2496d6acf...@k7g2000hsd.googlegroups.comfrom
Effix contained the following:
>
Quote:
Quote:
>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 /
>
Quote:
Don't worry about being confused, it probably has a lot to do with me
being lazy and not explaining properly.
>
Quote:
Look at this:
>
Quote:
foreach($filename_array as $filename){
$filename= substr(strrchr ($filepath,"/"), 0, 20) ;
...
>
Quote:
$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 '/'.
>
Quote:
So it should be:-
>
Quote:
foreach($filename_array as $filename){
//strip path so we just have filename
$filename= substr(strrchr ($filename,"/"), 1) ;
...
>
Quote:
--
Geoff Berrow *0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011http://slipperyhill.co.uk
>
Aaah I see now it makes a lot more sense :) I cant belive I didnt
figure that one out myself ofcourse its the filename that needs to be
stripped and not the path as I did.
Thank your very much for your help Geoff! :)- Skjul tekst i anførselstegn -
>
- Vis tekst i anførselstegn -
Is there anyway to sort the glob() by date rather than filename?
php.net says nothing about this. So my initial thought is to do
something like :
sorted_files=array()
foreach (glob(*.jpg)) as $filename) {
$sorted_files[$filename] = filemtime($filename)
arsort($sorted_files)

this is not finished code so i know it doesnt work but do you guys
think it will work?
-Effix
Geoff Berrow
Guest
 
Posts: n/a
#14: Aug 11 '08

re: I need help with my gallery


Message-ID:
<150d0cb8-511e-466a-a2ce-690ebc152779@d45g2000hsc.googlegroups.comfrom
Effix contained the following:
Quote:
>Is there anyway to sort the glob() by date rather than filename?
>php.net says nothing about this. So my initial thought is to do
>something like :
>sorted_files=array()
>foreach (glob(*.jpg)) as $filename) {
>$sorted_files[$filename] = filemtime($filename)
>arsort($sorted_files)
>
>this is not finished code so i know it doesnt work but do you guys
>think it will work?
It might work if you did this:

$sorted_files[filemtime($filename)] = $filename;
krsort($sorted_files);


--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk
Closed Thread