View Full Version : trouble creating a photo gallery
Reptar92
08-09-2012, 01:21 AM
so, I'm trying to learn how to write enough PHP in order to create a photo gallery,
I can't imagine that it would be too tough, all my jpegs are in one location. I just need to be able to scroll through them online is all. I'm not all sure where to start with this.
Ideally I'd love to see a basic premade script that I could use and have it explained to me so I can recreate it later.
Any and All help is appreciated.
keyboard
08-09-2012, 01:40 AM
Photo gallery's are normally programmed in Javascript...
If you want to use php to make a photo gallery, you'd have to put up with the page loading inbetween photos...
Is php really what you want?
Reptar92
08-09-2012, 01:57 AM
I don't care about the loading screen. it doesn't need to be too shiny. since my knowledge is about nil on both PHP and Java, which is the easiest way to accomplish a simply way to view photos from my browser
keyboard
08-09-2012, 02:49 AM
Php is probably the easiest..... probably
This works...
<?php
$imagearray[0] = 'src="FIRST IMG URL HERE" alt="FIRST IMG ALT HERE"';
$imagearray[1] = 'src="SECOND IMG URL HERE" alt="SECOND IMG ALT HERE"';
$imagearray[2] = 'src="THIRD IMG URL HERE" alt="THIRD IMG ALT HERE"';
$imagearray[3] = 'src="FOURTH IMG URL HERE" alt="FOURTH IMG ALT HERE"';
//Shouldn't need to edit past here
if(isset($_GET['img'])) {
$getval = $_GET['img'];
} else {
$getval = 0;
}
if(!is_numeric($getval)) {
die('<!DOCTYPE html><html><head></head><body>Invalid picture</body></html>');
}
if(!isset($imagearray[$getval])) {
die('<!DOCTYPE html><html><head></head><body>Invalid picture</body></html>');
}
$previous = $getval - 1;
$next = $getval + 1;
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img <?php echo $imagearray[$getval]; ?> >
<br />
<?php
if($getval == 0) {
echo '<a href=""><input type="button" disabled="true" value="Previous"></a>';
} else {
echo '<a href="?img=' . $previous . '"><input type="button" value="Previous"></a>';
}
if($getval == count($imagearray) - 1) {
echo '<a href=""><input type="button" disabled="true" value="Next"></a>';
} else {
echo '<a href="?img=' . $next . '"><input type="button" value="Next"></a>';
}
?>
</body>
</html>
Tell me if you want me to explain anything...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.