...

View Full Version : My PHP gallery not working, problem with explode.



tobiassjondin
05-11-2008, 04:10 PM
Ok so I made a gallery script in PHP and it worked, but I wanted to customize it even more so it presents name, size (width and height) and filetype based on image name (easy updating).
Well here's the code:


<?php
$count = 0;
if ($handle = opendir('sub/portfolio/abstract'))
{
while (false!== ($file = readdir($handle)))
{
if ($file!= "." && $file!= "..")
{
$fileexp = (explode("_",$file));
echo "<td align=\"center\"><a href=\"sub/portfolio/abstract/$file\"><img src=\"sub/portfolio/abstract/$file\" width=\"100\" height=\"100\" border=\"0\"></a><br />Name: $file[0]<br />Size: $fileexp[1]<br />Type: $fileexp[2]<br></td>";
$count = $count +1;
if ($count == 4)
{
echo "</tr><tr><td colspan=\"4\" style=\"background-color: #8b1300; height: 1px; border-top: 1px solid #ff2300; border-bottom: 1px solid #360700;\"></td></tr><tr>";
$count = 0;
}
}
}
echo "</table>";
closedir($handle);
}
?>

It explodes and works however the first returned array piece breaks at a place that I don't want.

If the pictures name is: Miracle of Birth_1280x1024_.jpg
it returns:

Name: M
Size: 1280x1024
Type: .jpg

There, the name is wrong and I don't know why since it should only break it up when it meets an underscore.

I could easily have just missed something, but I can't find it.

/Tobias

PappaJohn
05-11-2008, 04:45 PM
It is exploding properly, you have to use the 'exploded' array not the original variable.

Name: $file[0] should be Name: $fileexp[0]

tobiassjondin
05-11-2008, 04:56 PM
It is exploding properly, you have to use the 'exploded' array not the original variable.

Name: $file[0] should be Name: $fileexp[0]

Christ, well that seems quite reasonable :) what a miss. thanks mate.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum