micky1955 Posted June 17, 2013 Share Posted June 17, 2013 Hi all, help needed please. our site is http://www.1stwestpont.org.uk/photo_gallery3.php i am using the below code to display a menu of image directories stored on the server. on choosing an option it should ( and it used to! ) give the url for another bit of code to display the images. the directory names are stored in the array $darr[ ] having read the image directory. $lmen is just the number of directories. the variable $dirchoice is used to pass the value chosen to the display code but doesn't seem to be passed anymore. is this something to do with a newer version of PHP on my server perhaps? our site is http://www.1stwestpont.org.uk/photo_gallery3.php. i hope someboy can help me - this was my first foray into PHP and the code may not be the best but and as i said before, it used to work!! yours hopefully,, Micky <ul> <?php for ($x=0; $x<$lmen; $x++) { ?> <li><a href=<?php echo("$PHP_SELF?dirchoice=" . $darr[$x]) ?> ><?php echo(str_replace("_"," ",$darr[$x])); ?></a></li> <?php } ?> </ul> Quote Link to comment Share on other sites More sharing options...
trq Posted June 17, 2013 Share Posted June 17, 2013 Can we see the code that displays the images? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 17, 2013 Share Posted June 17, 2013 Have you tried switching to $_SERVER['PHP_SELF']? Side note: I would recommend staying away from PHP_SELF in this scenario for security reasons. More information can be found here: http://www.cyberscorpion.com/2012-03/why-php_self-should-be-avoided-when-creating-website-links/ The alternative would be to just use the page name. <li><a href=<?php echo("photo_gallery3.php?dirchoice=... If you really need to use PHP_SELF, you should look into sanitizing what the variable contains. Quote Link to comment Share on other sites More sharing options...
trq Posted June 17, 2013 Share Posted June 17, 2013 You don't need a filename. <a href="?dirchoice=<?php echo $darr[$x]; ?>"> I'm not convinced that is the issue though. Quote Link to comment Share on other sites More sharing options...
micky1955 Posted June 17, 2013 Author Share Posted June 17, 2013 Hi trq, thanks for looking at my problem. i've tried what you suggested (<a href="?dirchoice=<?php echo $darr[$x]; ?>">) with no luck. the directory name is not being stored in the variable $dirchoice. this bit is in photo_galley3.php and includes show_pics.php which i've shown below. if (isset($dirchoice)) { echo("dirchoice set"); $small_pic_dir = $dirchoice . "/" ."tns/"; /* $full_dir stores becomes chosen dir name plus thumbnail */ $full_dir="/home/ddm993c/public_html/1stwest/images/" . $small_pic_dir; $count = 1; $mydir = dir($full_dir); ?> <span class="text12"><p style="color:#CC0000"><?php echo(str_replace("_"," ",$dirchoice)); ?></p></span> <?php include ("show_pics.php"); echo "</table>"; $mydir->close(); } else { echo("dirchoice not set"); $dirchoice = "Big_Pit"; $count = 1; $small_pic_dir = $dirchoice . "/" ."tns/"; $full_dir="/home/ddm993c/public_html/1stwest/images/" . $small_pic_dir; $mydir = dir($full_dir); ?> <span class="text12"><p style="color:#CC0000"><?php echo(str_replace("_"," ",$dirchoice)); ?></p></span> <?php include ("show_pics.php"); echo "</table>"; $mydir->close(); } THIS IS show_pics.php: <?php while(($file = $mydir->read()) !== false) { if ($file !== "." && $file !== "..") { if ($count == 1) { $count++; $fstring = substr("$file", 0, -4); $smallpic = $small_pic_dir . "$file"; $smallpic = "images/" . $smallpic; $largepic = $large_pic_dir . "$file"; echo ("<table border=0 cellpadding=0 cellspacing=10 style=bordercolor=#111111 width=100%> <tr> <td width=25% align=center>"); ?> <img src="<?php echo($smallpic); ?> "width=240 height=172 /> <?php echo($fstring);?> </td> <?php } elseif ($count == 2) { $fstring = substr("$file", 0, -4); $smallpic = "$small_pic_dir" . "$file"; $smallpic = "images/" . $smallpic; $largepic = "$large_pic_dir" . "$file"; echo ("<td width=25% align=center>"); ?> <img src="<?php echo($smallpic); ?> "width=240 height=172 /> <?php echo($fstring);?> </td> <?php $count++; } elseif ($count == 3) { $fstring = substr("$file", 0, -4); $smallpic = "$small_pic_dir" . "$file"; $smallpic = "images/" . $smallpic; $largepic = "$large_pic_dir" . "$file"; echo ("<td width=25% align=center>"); ?> <img src="<?php echo($smallpic); ?> "width=240 height=172 /> <?php echo($fstring);?> </td> <?php $count = 1; } //end if ($count == 1) } // END if ($file !== "." && $file !== "..") } // END while(($file = $mydir->read()) !== false) ?> Quote Link to comment Share on other sites More sharing options...
Solution micky1955 Posted June 17, 2013 Author Solution Share Posted June 17, 2013 hi cyberRobot, thanks for looking at my problem. i see what you mean about $php_self and will stop using it altogether. my problem is that the directory name doesn't seem to be getting stored in the variable $dirchoice. this system used to work well. the site has not been used for some time but we want to bring it back online. Quote Link to comment Share on other sites More sharing options...
micky1955 Posted June 17, 2013 Author Share Posted June 17, 2013 solved thanks. needed $dirchoice = $_GET['dirchoice']; for some reason - never needed it before!! have discarded php_self as suggested and am simply using the page name as follows <li><a href=<?php echo("photo_gallery3.php?dirchoice=" . $darr[$x]) ?> ><?php echo(str_replace("_"," ",$darr[$x])); ?></a></li> Many thanks to both of you who replied. without some help from people such as yourselves it would be much, much more difficult to learn how to use a new language properly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.