Jump to content

db9

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by db9

  1. Hi thanks for the help. I tried echoing the $keyid like you said but all it does is output the right $keyid if the next arrow has been pressed but nothing if a thumbnail has been selected (as expected?) so I'm not really sure how that helps? The foreach loop is supposed to go through each picture in the array and check if the $keyid matches the one of the thumbnail clicked. Why is that redundant? Thanks again.
  2. I think what I want to do is have the GET['keyid'] bit check whether keyid has been set in my foreach loop or not yet before taking it from the url/setting it to zero. Is this possible/how would I do it? Thanks
  3. Hi, I think this is probably a logical error rather than a syntax one I have a function that displays the first image in a photo album in large and all the photos in it as thumbnails. I have a next and previous button that allows you to scroll through them (in large) and by clicking a specific thumbnail you can load that picture in large. My problem is that the pictures are stored in an array and the one to be shown large is selected by $keyid. My problem is that selecting a thumbnail resets the $keyid so that clicking next doesn't load the next image but the second. i.e. if you press the next arrow then click the 4th thumbnail and then click the next arrow again it loads the 2nd picture rather than the 5th as it should. How can I avoid this happening? This is my code: generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $Picturecount = (count(glob("" . $dir . "*.jpg")))/2; $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); $picture_array = glob("$dir*"); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $selected = str_replace('_th.jpg','.jpg',$thumbFile); foreach ($picture_array as $search){ $keyid = array_search($selected,$picture_array); $large = $picture_array[$keyid]; }} else{ if($keyid > (2*$Picturecount-1)){ $keyid = ($keyid - (2*$Picturecount));} if($keyid < 0){ $keyid = (2*$Picturecount+$keyid);} $large = $picture_array[$keyid];} echo " <tr><td><a href='?album=$album&keyid=" . ($_GET['keyid']-2) . "'>Previous</a></td><td></td><td align='right'><a href='?album=$album&keyid=" . ($_GET['keyid']+2) . "'>Next</a></td></tr> <tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr><tr><td height='50'></td></tr>"; Any help would be massively appreciated. Thanks very much!
  4. Hi, thanks a lot to anyone still reading this. I've changed my code a bit so I think it's easier to see what's going on. My problem now is basically that when I press next or previous the keyid is reset. I'd like it to carry on from the last thumbnail selected if one has been clicked. Would be very greatful if anyone can help me with this. Thanks This is my code: generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $Picturecount = (count(glob("" . $dir . "*.jpg")))/2; $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); $picture_array = glob("$dir*"); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $selected = str_replace('_th.jpg','.jpg',$thumbFile); foreach ($picture_array as $search){ $keyid = array_search($selected,$picture_array); $large = $picture_array[$keyid]; }} else{ if($keyid > (2*$Picturecount-1)){ $keyid = ($keyid - (2*$Picturecount));} if($keyid < 0){ $keyid = (2*$Picturecount+$keyid);} $large = $picture_array[$keyid];}
  5. Hi thanks for the continued help. I'm slowly getting further at the moment I've got it so that clicking the next arrow loads the next image in the appropriate space in large and clicking a specific thumbnail loads that image in large. However with the arrows I'm using a keyid variable to return the correctly sequenced picture from the array of pictures but with the thumbnails I'm just loading the file path. This obviously means that using both means the pictures aren't kept in sequence when scrolling through. i.e. if you press the next arrow then click the 4th thumbnail and then click the next arrow again it loads the 2nd picture rather than the 5th as it should. Is there a way to query the array so that I can take the thumbnail file path and use that to return the keyid that it corresponds to? This is my code: global $columns,$dir,$album; generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $large = str_replace('_th.jpg','.jpg',$thumbFile); } else{ if($keyid > (2*$Picturecount-1)){ $keyid = ($keyid - (2*$Picturecount)); } if($keyid < 0){ $keyid = (2*$Picturecount+$keyid); } echo " <tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr> <tr><td><a href='?album=$album&keyid=" . ($_GET['keyid']-2) . "'>Previous</a></td><td></td><td align='right'><a href='?album=$album&keyid=" . ($_GET['keyid']+2) . "'>Next</a></td></tr><tr><td height='50'></td></tr>"; $thumb_array = scandir($dir); foreach($thumb_array as $file){ if (strpos($file,'_th.jpg')){ ++$act; if ($act > $columns) { echo "</tr><tr><td width='160' height='120' align='center'><a href='?album=$album&thumb=$dir$file'><img src='".$dir.$file."' alt='".$dir.$file."'/></a></td>"; $act = 1; } else { echo "<td width='160' height='120' align='center'><a href='?album=$album&thumb=$dir$file'><img src='".$dir.$file."' alt='".$dir.$file."'/></a></td>"; } } } } Apologies if that wasn't explained very well and thanks again for all the help!
  6. Thanks for sticking with this. I realise this is a bit cheeky but I'm not really sure which bit of my code your bit replaces? This is what I'm using: function displayPhotos(){ global $columns,$dir,$album; generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $large = str_replace('_th.jpg','.jpg',$thumbFile); } else{ $picture_array = glob("$dir*"); $large = $picture_array[$keyid]; } echo $keyid; echo " <tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr> <tr><td><a href='?album=$album&keyid=" . ($_GET['keyid']-2) . "'>Previous</a></td><td></td><td align='right'><a href='?album=$album&keyid=" . ($_GET['keyid']+2) . "'>Next</a></td></tr><tr><td height='50'></td></tr>"; $thumb_array = scandir($dir); foreach($thumb_array as $file){ if (strpos($file,'_th.jpg')){ ++$act; if ($act > $columns) {L echo "</tr><tr><td width='160' height='120' align='center'><a href='?album=$album&thumb=$dir$file'><img src='".$dir.$file."' alt='".$dir.$file."'/></a></td>"; $act = 1; } else { echo "<td width='160' height='120' align='center'><a href='?album=$album&thumb=$dir$file'><img src='".$dir.$file."' alt='".$dir.$file."'/></a></td>"; } } } } Is there any chance you could show me what it should look like? Thanks again!
  7. Hi thanks for the hint. Unfortunately I don't know any javascript at all so I'd rather keep it all in php if at all possible. The efficiency thing isn't really a problem. Thanks again though!
  8. Hi Void, thanks very much I think I'm getting closer! I've changed my code to: function displayPhotos(){ global $columns,$dir,$album; generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $Picturecount = (count(glob("" . $dir . "*.jpg")))/2; $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $large = str_replace('_th.jpg','.jpg',$thumbFile); } else{ if($keyid > (2*$Picturecount-1)){ $keyid = ($keyid - (2*$Picturecount)); } if($keyid < 0){ $keyid = (2*$Picturecount-2); } $picture_array = glob("$dir*"); $large = $picture_array[$keyid]; } echo "<tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr> <tr><td><a href='?album=$album&keyid=" . ($_GET['keyid']-2) . "'>Previous</a></td><td></td><td align='right'><a href='?album=$album&keyid=" . ($_GET['keyid']+2) . "'>Next</a></td></tr><tr><td height='50'></td></tr>"; if ($handle = opendir("$dir")) { while (false !== ($file = readdir($handle))) { $file=$dir.$file; if (is_file($file)){ if (strpos($file,'_th.jpg')){ ++$act; if ($act > $columns) { echo "</tr><tr><td width='160' height='120' align='center'><a href='?album=$album&thumb=$file'><img src='".$file."' alt='".$file."'/></a></td>"; $act = 1; } else { echo "<td width='160' height='120' align='center'><a href='?album=$album&thumb=$file'><img src='".$file."' alt='".$file."'/></a></td>"; }}}}}} This seems to work as far as it goes my if statement doesn't work very well though. At the moment if the keyid goes above 2*the number of pictures then it doesn't go back to the start and if the keyid goes below 0 then it just gets set to zero permanently. Can you suggest a fix or a better way of doing this? Basically I want it to work so that if you're on the last picture and you click next it goes back to the start and if you're on the first and click previous it goes to the last (is there a way to reset the URL maybe?) Thanks a lot for the help! RussellReal, Thanks very much for the help am trying Void's solution at the moment as that seems to have almost cracked my problem but thanks again. The reason I have it scan the directory every time the page is loaded is because I want to be able to update it by just copying a new photo album into the appropriate folder and then having the page do everything else so obviously I need it to check whether anything new has been added whenever it's loaded.
  9. Sorry if I haven't explained this very well. That bit checks if a thumbnail image has been clicked on and if it has it finds the large version of the image clicked by striping the _th from the end and displays that picture in a separate space. That works fine but I'm trying to add backwards and forwards buttons so that you can use them to navigate through an album say, without having to click each thumbnail. I'm struggling to find a way to do it that doesn't break the bits I already have. Thanks again!
  10. Hi thanks very much for the help! I think I understand the gist of what you're saying but I'm not sure how to implement it. At the moment I don't actually have a loop displaying the large image at all. I have a loop that finds all the thumbnails (created in a separate function) and displays them and then the first bit either displays the first non-thumbnail image in the folder or if a thumbnail has been clicked then it displays the corresponding large image in place of the first. How could I introduce a loop to this? Thanks again!
  11. I have a function that reads all the picture files in a folder and displays them as thumbnails. It also displays a large version of the first image in the folder and clicking the thumbnail changes the large picture. I'm trying to use pictures of arrows as a button to allow users to click and have the next picture displayed large rather than having to click each individual thumbnail but don't really know how to get started. Can anyone suggest a method or give me a hint? This is my code so far if that helps: function displayPhotos(){ global $columns,$dir,$album; generateThumbnails(); $act = 0; $keyid = 0; $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $large = str_replace('_th.jpg','.jpg',$thumbFile); } else{ $picture_array = glob("$dir*"); $large = $picture_array[$keyid]; } echo "<tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr> <tr><td><img src='gallery/icons/arrow-blue-rounded-left.jpg' alt='Previous'></td><td></td><td align='right'><img src='gallery/icons/arrow-blue-rounded-right.jpg' alt='Next'> </td></tr><tr><td height='50'></td></tr>"; if ($handle = opendir("$dir")) { while (false !== ($file = readdir($handle))) { $file=$dir.$file; if (is_file($file)){ if (strpos($file,'_th.jpg')){ ++$act; if ($act > $columns) { echo "</tr><tr><td width='160' height='120' align='center'><a href='?album=$album&thumb=$file'><img src='".$file."' alt='".$file."'/></a></td>"; $act = 1; } else { echo "<td width='160' height='120' align='center'><a href='?album=$album&thumb=$file'><img src='".$file."' alt='".$file."'/></a></td>"; } } } } } } Thanks very much to anyone having a look at this!
  12. I'm trying to make use of some code for a simple photo gallery but I'm running into problems because the photos are no longer all stored in the same directory as the function script. If anyone could have a look through and let me know where I'm going wrong I'd be very grateful. Thanks in advance! [attachment deleted by admin]
×
×
  • 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.