How to choose images from a dropdown list

18.4.2. How to choose images from a dropdown list

Isn't it more comfortable being able to choose the image for your review (if you are an administrator) from a dropdown list that offers the names of all available images in your image directory, rather than having to enter the full URL to the image each time? You could easily incorporate this functionality if you just cut and pasted the code from the admin/modules/topics.php file. The functionality is in the Topics module already - you don't need to write full URLs to the topics icons, do you?

The relevant part in the Reviews to introduce the code from the Topics module is the following code in modules/Reviews/index.php:

    if(is_admin($admin)) {
        echo "
        <input type=\"text\" name=\"cover\" size=\"40\" maxlength=\"100\"><br>
Replace it with:
    if(is_admin($admin)) {
        echo "
        echo "<select name="cover">";
        $path1 = explode ("/", "images/reviews/");
        $path = "$path1[0]/$path1[1]";
        while ($file = readdir($handle)) {
          if ( (ereg("^([_0-9a-zA-Z]+)([.]{1})([_0-9a-zA-Z]{3})$",$file)) 
            AND $file != "AllTopics.gif") {
            $tlist .= "$file ";
        $tlist = explode(" ", $tlist);
        for ($i=0; $i < sizeof($tlist); $i++) {
          if($tlist[$i]!="") {
            if ($topicimage == $tlist[$i]) {
              $sel = "selected";
            } else {
              $sel = "";
            echo "<option name="cover" value="$tlist[$i]" $sel>$tlist[$i]n";
        echo "</select><br>";
        echo "<i>"._RIMAGEFILEREQ."</i><br><br>

The part of code that was stolen from the Topics module (from the admin/modules/topics.php file) is between the blank lines in the above code. It will offer you a dropdown list of all images in the images/reviews folder. Just like with the topics images, you must use all small letters and no underscores or other special characters. See choose image for review.

Help us make a better PHP-Nuke HOWTO!

Want to contribute to this HOWTO? Have a suggestion or a solution to a problem that was not treated here? Post your comments on my PHP-Nuke Forum!

Chris Karakas, Maintainer PHP-Nuke HOWTO


Site Info v2.2.2

Last SeenLast Seen
  • neralex
  • yhya
Server TrafficServer Traffic
  • Total: 376,999,117
  • Today: 60,884
Server InfoServer Info
  • Feb 18, 2019
  • 11:39 pm CET