robszol Posted April 25, 2006 Share Posted April 25, 2006 OK, So let's say I have a folder named Gallery with files (1.jpg, 2.jpg, 3.jpg, 4.jpg etc...)and I want to create a webpage where:1). Creates a table with X row and 5 columns2). The table's size is dependant on the files present in the folder "Gallery"3). I want the pictures to be thumbnail size in the table4). Each thumbnail links to original picture (1.jpg or 2.jpg etc.)5). if step 4 is too tough then I could have a seperate folder called "Thumbnails" with files (thumb1.jpg, thumb2.jpg etc...) linking to (1.jpg, 2.jpg etc) respectively.so If I have 32 pictures in the Gallery folder then in the webpage, I'll have32 thumbnail sized pictures in a table with 5 columns and 7 rows and the 7th row has 2 pics and the rest of row is blank.How the bleep can I do this? I'm also new to PHP (but I know C++ to give u an idea of how much knowledge I have) and maybe PHP is too tough and perhaps there is a better way, but yeah [b]I need your help!! !![/b]THANKS!!!!!! Link to comment https://forums.phpfreaks.com/topic/8409-creating-gallery-based-on-number-of-files-in-folder/ Share on other sites More sharing options...
onepixel Posted April 26, 2006 Share Posted April 26, 2006 [!--quoteo(post=368648:date=Apr 25 2006, 05:14 PM:name=Robby)--][div class=\'quotetop\']QUOTE(Robby @ Apr 25 2006, 05:14 PM) [snapback]368648[/snapback][/div][div class=\'quotemain\'][!--quotec--]OK, So let's say I have a folder named Gallery with files (1.jpg, 2.jpg, 3.jpg, 4.jpg etc...)and I want to create a webpage where:1). Creates a table with X row and 5 columns2). The table's size is dependant on the files present in the folder "Gallery"3). I want the pictures to be thumbnail size in the table4). Each thumbnail links to original picture (1.jpg or 2.jpg etc.)5). if step 4 is too tough then I could have a seperate folder called "Thumbnails" with files (thumb1.jpg, thumb2.jpg etc...) linking to (1.jpg, 2.jpg etc) respectively.so If I have 32 pictures in the Gallery folder then in the webpage, I'll have32 thumbnail sized pictures in a table with 5 columns and 7 rows and the 7th row has 2 pics and the rest of row is blank.How the bleep can I do this? I'm also new to PHP (but I know C++ to give u an idea of how much knowledge I have) and maybe PHP is too tough and perhaps there is a better way, but yeah [b]I need your help!! !![/b]THANKS!!!!!![/quote]1- First read the folder containing your pictures to retrieve that full-size files name. Verify sure the filename does not contain the string "thumb" before storing that file name in an array.use the stripos ( $filename, 'thumb') function to make sure the returned value is FALSEfunction GetPictures($dir){$picturearray=array();if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(! stripos ( $file, 'thumb') ){$picturearray[]=$file; } }//end while loop closedir($dh); }}return $picturearray;}//end function No need to have two folders for the thumbnails and the full-size pictures. Just create a filter that will allow your script to know the difference.2- Once you have that array of full picture file name, pass it to a function that can loop through to create the table string.function CreateTableString($filearray, $folderpath){$n=count($filearray);$Str='<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr>';foreach($filearray as $k=>$file){if($k>0 && $k%4==0){$Str.='</tr><tr>'; }$Str.='<td align="left" valign="top"><a href="'.$folderpath.'/'.$file.'"><img src="'.$folderpath.'/thumb'.$file.'" width="80" height="80" border="0"></a></td>';}$r=($n%5);if($r>0){$Str.='<td colspan="'.$r.'"></td>';}$Str='</tr></table>';return $Str;}$Folderpath='path to the folder containing your pictures'; //basolute or relative to the current PHP script$Picturearray=GetPictures($Folderpath);$TableStr=CreateTableString($Picturearray, $Folderpath); // this is your thumbnails table stringDoes not matter how many pictures you have. The only restriction is the correlation between the tumbnail and the full-size picture names.I hope this will helps. Link to comment https://forums.phpfreaks.com/topic/8409-creating-gallery-based-on-number-of-files-in-folder/#findComment-31138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.