Jump to content

busnut

Members
  • Posts

    128
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

busnut's Achievements

Member

Member (2/5)

0

Reputation

  1. thankyou salathe, very much appreciated. I'll look at your revised edition tomorrow. In a lot of the stuff I code, I always seem to take the long way, its only because of my limited knowledge in php although slowly growing and only dealing with such when i'm asked to do new or improved websites which doesn't happen all that often. Thanks one again to all those involved in helping me achieve a good result, much appreciated!
  2. Wholly understand, I do have to apologies about the lack of information (personal issues crossing paths with getting the job done, so please accept my apologies). The script listed above is one i've used for my photo gallery. The photo gallery does have subfolders, whereas this script, the images of the front page of our newsletter for the group I belong to is just in a folder titled 'journals'. In that folder, is a bunch of images (all .jpg) of the front page of each journal. They are all named yyyy-mm.jpg (so 2010-10.jpg, 2010-08.jpg etc etc). However, that code you supplied fixed the issue and all the images now display in descending order, so very much appreciated. As the code is the same (albeit the change i've just made) for the gallery script, I know there are areas that are not required, like the <h2>$category</h2> reference as they are all in one directory, as aposed to the gallery script that relies on this. What else in the code is really un-necessary?
  3. It's the same code above, but here it is again with the rsort statement in it. I've tried numerous places, all to no avail. It's like it needs to be with something, just what not sure. <h1>Our Journals</h1> <p>QOCS members received elevyn (11) 16 page publications a year, with news & events from the past to present, including stories and images from members and fleet change information within the industry.</p> <p>Below are some of our past journal covers. <em>Please note that most of the journals are printed in black & white to save money so we can pool the funds towards restoring our fleet.</em> </p> <p> <? $dir = "journals"; $text = "journals.txt"; $cols = 3; $colswidth = 33; $fh=fopen($text, "r"); while(!feof($fh)) { $temp = explode("|", $line); $title[$temp[0]] = $temp[1]; $line=fgets($fh); unset($temp); } function ListFiles($dir) { if($dh = opendir($dir)) { $last_cat = ''; $files = Array(); $inner_files = Array(); while($file = readdir($dh)) { if($file != "." && $file != ".." && $file[0] != '.') { if(is_dir($dir . "/" . $file)) { $inner_files = ListFiles($dir . "/" . $file); if(is_array($inner_files)) $files = array_merge($files, $inner_files); } else { array_push($files, $dir . "/" . $file); } } } closedir($dh); return $files; } } foreach (ListFiles($dir) as $key=>$file){ rsort($file); if (preg_match("/.jpg/", $file)) { if($last_cat != $category[$file] && $category[$file]<>"") { echo "<h2>$category[$file]</h2>"; $last_cat = $category[$file]; } if ($title[$file]<>"") { echo "<a href=\"$file\" rel=\"lightbox\" title=\"$title[$file]\"><img src=\"gallery-thumbs.php?file=$file\"></a> "; } else echo "<a href=\"$file\" rel=\"lightbox\"><img src=\"gallery-thumbs.php?file=$file\"></a> "; } } ?> </p>
  4. one that commonly comes up is: Warning: rsort() expects parameter 1 to be array, string given in public_html/testing/test/journals.php on line 48
  5. This is where i'm getting into trouble. I've read up on sort & rsort & asort, and whilst rsort seems the most logical for what I'm trying to achieve, I keep getting errors, so somewhere its like I need some sort of keyval thing (if that makes any sense) and to know in which part it should go?
  6. Actually, to rephrase on the sorting of the date, if possible can it be in decending order, so that way the latest named images are displayed first? Thankyou
  7. G'day, just .jpg files and sort by the file name only. I actually have 2 of these scripts running. The first is for our monthly newsletter which all the front pages of the newsletter are just in one directory, the other is running the gallery, but that one works fine - i just need the sort feature fixed for this one only.
  8. Ok, that sort of makes sense, however I should've mentioned this before, whilst all the file names are in yyyy-mm format, because i'm making up the page & getting all the images, the images themselves are picked at random, so I might edit 2010-04 before I edit 2010-01 if that makes sense, as the images appear to display in the format of when they were last edited/updated rather than the filename itself.
  9. I've tried sorting different ways and putting the sort command in various places, it's just I really have no clue on sorting. I do get this error quite often whe trying to sort Warning: sort() expects parameter 1 to be array, null given in images.php on line 47
  10. G'day again. I've been looking up the php function on sorting, and to be totally honest I have no idea on how to implement it into my existing script which looks at a directory/sub directories and displays images. The files are named 2010-01.jpg, 2010-02.jpg etc (so another words yyyy-mm format) Can anybody help me? The script work perfectly otherwise, just doesn't put things into an order. Below is the code: <? $dir = "images"; $text = "images.txt"; $cols = 3; $colswidth = 33; $fh=fopen($text, "r"); while(!feof($fh)) { $temp = explode("|", $line); $title[$temp[0]] = $temp[1]; $line=fgets($fh); unset($temp); } function ListFiles($dir) { if($dh = opendir($dir)) { $last_cat = ''; $files = Array(); $inner_files = Array(); while($file = readdir($dh)) { if($file != "." && $file != ".." && $file[0] != '.') { if(is_dir($dir . "/" . $file)) { $inner_files = ListFiles($dir . "/" . $file); if(is_array($inner_files)) $files = array_merge($files, $inner_files); } else { array_push($files, $dir . "/" . $file); } } } closedir($dh); return $files; } } foreach (ListFiles($dir) as $key=>$file){ if (preg_match("/.jpg/", $file)) { if($last_cat != $category[$file] && $category[$file]<>"") { echo "<h2>$category[$file]</h2>"; $last_cat = $category[$file]; } if ($title[$file]<>"") { echo "<a href=\"$file\" rel=\"lightbox\" title=\"$title[$file]\"><img src=\"gallery-thumbs.php?file=$file\"></a> "; } else echo "<a href=\"$file\" rel=\"lightbox\"><img src=\"gallery-thumbs.php?file=$file\"></a> "; } } ?>
  11. Worked perfectly, with a small alteration: <?php function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); $num = array_rand($ar); return $ar[$num]; } function getImagesFromDir($dir) { $cur_level_dirs = glob($dir . '/*', GLOB_ONLYDIR); $cur_level_files = glob($dir . '/*.{jpg,gif,png}',GLOB_BRACE); foreach ($cur_level_dirs as $nxt) { $cur_level_files = array_merge($cur_level_files,getImagesFromDir($nxt)); } return ($cur_level_files); } $root = 'gallery/'; // If images not in sub directory of current directory specify root //$root = $_SERVER['DOCUMENT_ROOT']; // Obtain list of images from directory $imgList = getImagesFromDir($root); $img = getRandomFromArray($imgList); ?> Thanks for the assistance, much appreciated
  12. G'day, on the home page of a website i'm building, i'm wanting to have a random photo that looks at all the subfolders of the gallery directory, but the best I can achieve is just one subfolder. Here is the code, if anyone can assist, that'll be appreciated. <?php function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); $num = array_rand($ar); return $ar[$num]; } function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } $root = ''; // If images not in sub directory of current directory specify root //$root = $_SERVER['DOCUMENT_ROOT']; $path = 'gallery/topic1/'; // Obtain list of images from directory $imgList = getImagesFromDir($root . $path); $img = getRandomFromArray($imgList); ?> <center><a href="?GoTo=Photo Gallery"><img src="<?php echo $path . $img ?>" alt="" height="267" width="400"/></a></center>
  13. Got it working, FINALLY. Thanks to jl5501 for the snippet of code, instead of just moving the <h2> line, i've moved the whole bit about if last cat section to below the foreach statement. Attached is the code: gallery.php <h1>Photo Gallery</h1> <? $dir = "gallery"; $text = "gallery.txt"; $cols = 3; $colswidth = 33; $fh=fopen($text, "r"); while(!feof($fh)) { $temp = explode("|", $line); $title[$temp[0]] = $temp[1]; $description[$temp[0]] = $temp[2]; $photographer[$temp[0]] = $temp[3]; $category[$temp[0]] = $temp[4]; $line=fgets($fh); unset($temp); } function ListFiles($dir) { if($dh = opendir($dir)) { $last_cat = ''; $files = Array(); $inner_files = Array(); while($file = readdir($dh)) { if($file != "." && $file != ".." && $file[0] != '.') { if(is_dir($dir . "/" . $file)) { $inner_files = ListFiles($dir . "/" . $file); if(is_array($inner_files)) $files = array_merge($files, $inner_files); } else { array_push($files, $dir . "/" . $file); } } } closedir($dh); return $files; } } foreach (ListFiles($dir) as $key=>$file){ if (preg_match("/.jpg/", $file)) { if($last_cat != $category[$file] && $category[$file]<>"") { echo "<h2>$category[$file]</h2>"; $last_cat = $category[$file]; } if ($title[$file]<>"") { echo "<a href=\"$file\" rel=\"lightbox\" title=\"$title[$file]<br>$description[$file]<br>© $photographer[$file]\"><img src=\"gallery-thumbs.php?file=$file\" height='100' width='150'></a> "; } else echo "<a href=\"$file\" rel=\"lightbox\"><img src=\"gallery-thumbs.php?file=$file\" height='100' width='150'></a> "; } } ?> gallery-thumbs.php <?php // define directory path $image = exif_thumbnail($_GET['file']); header("Content-Type: image/jpeg"); echo $image; ?> And then with the description text file, upload it to the same directory as the gallery.php & gallery-thumbs.php directory in this format: gallery/subfolder name/file name.jpg|title|description|copyright|category And remember to upload your images under the 'gallery' folder then in their subfolders. then to get the lightbox working, download lightbox (search google) and implement some css to go with it. Thanks once again
  14. didn't notice that myself, so i've changed that, still no luck sorry
  15. unfortuneatly it still isn't displaying the category. I've put the <h2> line in every position possible, with only down below the 'foreach' statement does it show the category, but shows it for every image
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.