Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Dal123

macrumors 6502a
Original poster
Oct 23, 2008
903
0
England
I'm following an excellent tutorial on youtube http://www.youtube.com/watch?v=IUh2uFjoeKE&playnext=1&videos=OidNLx_cEt8 and I'm up to part 3 where I am actually fetching the data in my album structure:
data)contains): - album1, album2, album3, album4, thumbs
album1,2,3,4 (contains pics specified)
thumbs (contains all pics with same filenames as they are in albums but are just a heap of pics; as opposed to organized like in albums). So the php must determine what files are needed then grab them through thumbs. I would've thought that they needed to be in folders like in albums but - this guy is obviously a pro and it's clearly do-able how he's done it and I'm not knocking as it's by far better to save organising a load more folders when the computer can do the work:p - it's just I can't understand it at the moment.
Back to topic I manage to get to the stage where I can call out the filenames in the folder, but I cannot manage to get the images to be displayed. I can display the albums and resize them as thumbnails but with lightbox in the later stage - will not work properly and I should be able to follow the tutorial as it's done and bit lost here.
The only way I have deviated is I created not to show files called '.DS_Store' as I was somehow showing up hidden files presumably created by camera. I removed this code and still didn't work so must be different error. Here it is live http://www.preciseformwork.co.uk/hard/album.php
I must have a little comma out or something but cannot find what I've done as searched the code on youtube and can't see where I've gone wrong yet. I am not to the stage of installing lightbox yet which looks very simple.
Out of interest would it be more seo friendly to create this as a database with categorised sections?
Any input welcomed :D.
PHP:
<html>
<head>
</head>
<body>
<?php
$page = $_SERVER ['PHP_SELF'];

//settings
$column = 5;

//directories
$base = "data";
$thumbs = "thumbs";

//get album
$get_album = $_GET['album'];

if (!$get_album)
{
echo "<p>select an album<p/>";
$handle = opendir($base);
while (($file = readdir($handle)) !==FALSE)
{
if (is_dir($base."/".$file) && $file != "." && $file != ".." && $file != $thumbs)
{
echo "<a href='$page?album=$file'>$file</a></br>";
}
}
}

else
{
if (!is_dir($base."/".$get_album) || strstr($get_album,".") !=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL)
{
echo "Album does not exist";
}
else
{
echo "<b>$get_album</b></p>";
$handle = opendir($base."/".$get_album);
while (($file = readdir($handle)) !== FALSE)
{
if ($file != "." && $file != ".." && $file != ".DS_Store")
{
echo "<img src='$base/$thumbs/$file'></br>";
}
}
}
}

?>
</body>
</html>
 
Ok I just gave the album on your site a quick glance. It seems that the thumbs aren't loading in your albums as your thumbs are PNG files while your album is looking for JPG files.

This is the error coming up ...
Code:
The requested URL /hard/data/thumbs/lw-131.jpg was not found on this server.

And when I checked that directory the file is actually ...
Code:
/hard/data/thumbs/lw-131.png

You created these thumbs manually yourself yes? So from this I'm guessing if you convert the thumbnail png files in your thumbs directory to jpg files it will work.
 
That script is working as it should and displays an album that grabs other albums and runs itself - if you know what I mean - probably not as I'm not very good at explaining:eek:.
What I want is it only to load the album specified, even I'm confusing myself as that is what it does :eek:.
I want to display the thumbnails directory, linked to the real album, and simply display this on the page, without the option of jumping from album to album.
Anyone understand what I mean :eek:?
This is what I think it's along the lines of though I am obviously wrong as it does not work lol
PHP:
<?php
$page = $_SERVER ['PHP_SELF'];
// settings
$base = "data";
$thumbs = "thumbs";
$handle = opendir($base);
$get_album = $_GET['album'];
$handle = opendir($base);

while (($file = readdir($handle))
if (is_dir($base."/".$file) && $file != ".")
echo ""<img src='$base/$thumbs/$file'></br>";

?>
 
PHP:
echo ""<img src='$base/$thumbs/$file'></br>";

Well, for starts, that's an extra double quote at the start:

PHP:
echo "<img src='$base/$thumbs/$file'></br>";

You can run your PHP code from the command line on the server, or your Mac, like this:
'php -l foo.php' and it will tell you of the first syntax error and what line it's on. Fix and re-run. PHP can be configured to give helpful error messages on the web, but it's disabled on production servers for security reasons.

The only way I have deviated is I created not to show files called '.DS_Store' as I was somehow showing up hidden files presumably created by camera.

FYI:
.DS_Store files are from your Mac. Run an 'ls -la' command from the Terminal on your Mac, and you'll see one in any directory that's ever been opened in the Finder.
 
Thanks, terminal thing was pretty impressive. "php -l foo.php" I'm testing locally on my machine with mamp and don't think that will work. Just googled it and not much info on it. Where would I put that to test live?
 
The closest I got to getting this to work is like this however it's not spot-on as I want the album names to be variables and change themselves. See where I say
PHP:
$handle = opendir('data/album1');
Need this as variables I think and probably some more code.
Anyone got any ideas, I've been working on it all week full days and really need to get it done by the weekend. Any advice appreciated, obviously bit complex for me, I've watched countless tutorials, taken pages and pages of notes but still struggling. Seems like arrays with loops, parameters with functions are being used :eek:.
PHP:
<?php
$handle = opendir('data/album1');
while ($file = readdir($handle))
{
if ($file != "." && $file != ".." && $file != ".DS_Store") 
{
echo "<img src='data/album1/thumbs/$file'>";
}
}
?>
 
You'll want to double paren your while so that it evaluates the entire expression rather than just $file. It's an order of operations thing.
PHP:
while ( ($file = readdir($handle)) )
Also, here's a simplification of your if statement that just looks for files that begin with a dot (hidden files).
PHP:
if (substr($file, 0,1) != '.' )
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.