Page 1 of 1
Windows and Linux
Posted: Fri Oct 28, 2011 3:07 am
by Romulas
Why does this code works fine in winows and not in Linux,it should display a number of thumbnails
which it does in windows, but in Linux it only shows 1 thumbnail ? The print_r displays the right
number of entries.
$images = "thumbs/$name/";
$big = "gallery/$name/";
if($handle=opendir($images)) {
while(false!==($file=readdir($handle))) {
if($file !=="."&&$file !=".."&&$file !=rtrim($big,"/")) {
$files[]=$file;
}
}
closedir($handle);
}
//print_r($files);
echo'<table width="100%" cellspacing="3"><tr>';
$cols = 6;
$colCtr = 0;
foreach($files as $file) {
if($colCtr % $cols == 0){
echo'</tr><tr><td colspan="6"><hr/></td></tr><tr>';
echo'<td align="left"><a href="gallery/'.$name.'/'.$file.'"><img src="thumbs/'.$name.'/'.$file.'"/></a></td>';
$colCtr++;
}
}
echo'</table>';
?>
Re: Windows and Linux
Posted: Fri Oct 28, 2011 5:57 pm
by jacek
It might be that the path is wrong, if you view the source of the generated page does the HTML look like it should ? Also you may want to look into using the
scandir or
glob functions since your method is fine, but a bit php4.
Re: Windows and Linux
Posted: Thu Nov 03, 2011 12:46 am
by Romulas
Hi Jacek
I have tried your suggestions and have'nt been able to fix my problem, so i looked in other places.
I removed the if statement
if($colCtr % $cols == 0){
this allows the images to be diisplayed but in a list view, which is not what i want. There is nothing wrong with the if
statement, so why does linux display one image then stop, 2 mod 6 == o therefore
it should not stop. Is there a fault with my logic or does the problem lie some where else, maybe the html code.
As usual thank you for your help
Re: Windows and Linux
Posted: Thu Nov 03, 2011 5:39 pm
by jacek
Well the problem is not with the OS, so what else is changing ?
Are you using the same browser to view the page both times ?
The HTML you are using is not the best, so a good start might be to look at the source of the page to see what is being ouput and make sure it is valid.
I would write what you are trying to do like this, taking a slightly different approach.
<?php
$files = scandir($images);
unset($files[0], $files[1]);
$rows = array_chunk($files, 6);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
a, img {
float: left;
border: none;
}
</style>
<title>My Gallery !</title>
</head>
<body>
<?php
foreach ($rows as $row){
echo '<div>';
foreach ($row as $image){
echo '<a href="gallery/', $name, '/', $image, '"><img src="thumbs/', $name, '/', $image, '" /></a>';
}
echo '</div>';
}
?>
</body>
</html>
The array_chunk() splits the list of files up into blocks of 6.
Re: Windows and Linux
Posted: Sat Nov 05, 2011 12:07 am
by Romulas
Thanks Jacek
Your code works really well.
Iwould really like to display the names of the images aswell, I am considering
using the exif function to get the names,what do you think or what would you suggest.
Is there a better way, hopefully eaiser.
Thank you
Re: Windows and Linux
Posted: Sat Nov 05, 2011 7:51 pm
by jacek
You should have the names already, in the $image variable. Can you just use that ?