Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

I need a simple PHP image gallery script


Barbaneez
 Share

Recommended Posts

Hey, I'm kinda new to PHP but I've tried to code what you asked for. Here it is:

 

EDIT: Updated V0.4b

 

"Barb's Galery Version 0.4b RELEASE 2"!!! (Released under the GNU General Public License)

-----------

 

Change Log:

 

V0.4

 

•Thumbnailing fixed (this time fo' real)

•Changed "filectime" for "filemtime"

 

V0.3

 

•Some stuff fixed

•Some stuff added

•Thumbnailing in IE fixed (kinda)

 

V0.2

 

•Page's index added

•Images per page select list added

•^^Both validated

•Fixed LOTS of things

 

-----------

 

Customizable Features:

 

•Directory form where the images are taken

•Image's File Types

•Number of images per page

•Number of columns

•Size of thumbnails

 

-----------

 

Known Issues:

 

It uses "filectime" instead of "filemtime" function, this is the only way it will show the last added images. But it seems this doesn't work very well since sometimes some images aren't even listed. THIS IS A VERY IMPORTANT ISSUE ANY HELP WILL BE APRECCIATED I decide to use "filemtime" because it's more important to show all images, plus if this is going to be in remote server, the last mod time is the time they are uploaded so that's what we were looking for.

•Thumbnails are just a sized down version of the image, so it must load the big image to show it. I don't know any way an image could be thumbnailed other than this. This could be a pro because when you click the image to see it real size it is already cached. EDIT: Thumbnailing doesn't work in IE. Damn You M$ angry.gif . FIXED The only way I managed to fix it is is fixing the size of each image, meaning no matter if it was a huge or tiny pic it will show always the same size (100x100 in this case). DOUBLE FIX image are now scaled down proportionally.

 

-----------

 

Remember this is a Beta (meaning it's something I managed to put together a couple of hours before I went to bed) so anyone is free to finish/modify/improve this code in any way.

 

Enough of that, here's the code: (I'll work more on it maybe tomorrow or in 2 days)

 

 

<html><body><div id="container" style="text-align:center;"><?php/*	Images' Vars	*/$img_per_page = (int) $_GET['perpage'];$default_perpage = 20;  // In case $img_per_page is not specified or not valid$page = (int) $_GET['page'];$cols = 5;$max_width = 100;$max_height = 100;/*	Files' Vars  */$dir = "galery";$file_types = array(".gif", ".jpg", ".jpeg", ".png", ".bmp");$img_files = array();/*	Puts all the names of the files from $dir in $files	*/$files = scandir($dir);reset($files);foreach ($files as $file) { foreach ($file_types as $type) {  	/*	Looks for the extension to be an image type	*/ 	if (strripos($file, $type) >= (strlen($file) - 5)) { 	   /*	if it is an image the filename is stored in $img_files, the $index being the timestamp for the last modification	*/   $index = filemtime($dir . "/" . $file);   $img_files[$index] = $file;    	} }}/*	Sorts the array by its indexes in reverse order, meaning that the values with higher timestamps (last modificated files) will be at the beggining	*/krsort($img_files);reset($img_files);/*	Counts how many images are in the array and creates a new one ($images) with 1 - $count indexes	*/$count = count($img_files);$images = range(1, $count + 1);$index = 1;/*	Starting from the beginning each image filename is put in $image	*/foreach ($img_files as $img) { $images[$index] = $img;  ++$index;}/*	Validates $img_per_page	*/if (($img_per_page < 1) || ($img_per_page > 100)) {$img_per_page = $default_perpage;}/*	Calculates how many pages are nedeed	*/$max_page = ceil($count / $img_per_page);/*	Validates $page  */if ($page < 1) {$page = 1;}elseif ($page > $max_page) {$page = $max_page;}/*	Calculates $from and $to which image it will show according to the $page	*/$from = (($page - 1) * $img_per_page) + 1;$to = $page * $img_per_page;/*	If the last image to show is higher than the $count of $images it is shortened	*/if ($to > $count) {$to = $count;} ?><table><tr><?php/*	Each td is written	*/for ($index = $from; $index <= $to; ++$index) {  $path = $dir . "/" . $images[$index];  /*	Get's the size in pixels of the image	*/ list($width, $height) = getimagesize($path);  /*	If it's too big it's thumbnailed proportionaly	*/ if ($height > $max_height || $width > $max_width) {  	$prop = $height / $width;  	if ($height >= $width) { 	   $height = $max_height;   $width = round($height / $prop); 	} else {   $width = $max_width;   $height = round($prop * $width); 	} }   $img_style = "\"border:0;height:" . $height . ";width:" . $width . ";\""; $td_style = "\"text-align:center;height:" . $max_height . ";width:" . $max_width . ";\"";  echo "<td style=" . $td_style . "><a href=\"" . $path . "\"><img style=" . $img_style ." src=\"" . $path . "\" alt=\"" . $images[$index] . "\" /></a></td>\n";  /*	If $index - $from + 1 mod $cols is zero it means that the image just shown was on the right-most column, so it starts a new row  */ if ( (($index - $from) + 1) % $cols == 0) { echo "</tr>\n<tr>\n"; } }?></tr></table><div id="index"><?php	/*	The page index is written. It's something like "<< < 1 2 3 4 5 > >>"	*//*	Header for the links	*/$path = "?perpage=" . $img_per_page . "&page=";/*	If it's not the first page the left arrows are shown	*/if ($page > 1) { echo "<a href=\"" . $path . '1' . "\"><<</a>\n"; echo "<a href=\"" . $path . ($page - 1) . "\"><</a>\n";	}/*	Shows the number of each page with a link to it	*/for ($i = 1; $i <= $max_page; ++$i) { /*	The current page is not linked	*/ if ($i <> $page) { echo "<a href=\"" . $path . $i . "\">" . $i . "</a>\n";} else { echo $i . "\n"; }}/*  If it's not the last page the right arrow is shown	*/if ($page < $max_page) { echo "<a href=\"" . $path . ($page + 1) . "\">></a>\n"; echo "<a href=\"" . $path . $max_page . "\">>></a>\n";}?></div><div id="bottom"><div id="form-container" style="float:left;"><form name="pageinput" method="GET"><input type="hidden" name="page" value="<?php echo $page ?>">Images per page:<select name="perpage"><option>5</option><option>10</option><option>20</option><option>50</option><option>100</option></select><input type="submit" value="Go"></form></div><div id="page-numbers" style="float:right;"><?php echo "Viewing images " . $from . " to " . $to . " of " . $count . "." ?></div></div></div></body></html>

 

 

PS: Probably someone will come up with a way better code in any minute. Hey, atleast I tried.

Edited by facugaich
Link to comment
Share on other sites

userbars_suck

Just use MySQL. I'd write a script if I could be arsed, just make a form to query the server to receive from your MySQL database.

 

 

$name=$_POST['n'];$description=$_POST['d'];$nigga=mysql_connect('localhost','yournigga','yourniggapass');if (!$nigga) {die('nigga cant connect');}else {print 'adding image...';$lequery='INSERT INTO your_nigga_database VALUES(' + $_FILES['name'] + $_FILES['extension'] ') ',' + stripslashes($description) + ',' + stripslashes($name) + ')';mysql_query($lequery);print 'added image';}

 

Not even sure if that's valid but that's just a five minnute dealio. I'll fix it when I can.

Link to comment
Share on other sites

If you're still looking, this might be helpful. I think there's a few mistakes (only works with jpg at the moment etc.), but I can fix them up if you want to use it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.