This topic is locked

Image Select Box

11/4/2006 6:36:25 PM
PHPRunner General questions
S
seangates author

I have a weird dilemma. I have just converted one of my clients' administration pages to the new PHPRunner 3.1. One of the fields in the products table holds the path to the product image.
My problem is that I used to have a select box for them that was populated by the following code:

<select name="image_path" id="image_path">

<?php

function searchdir ($path, $maxdepth = -1, $mode = "FULL", $d = 0) {

if (substr($path, strlen($path) - 1) != '/') { $path .= '/'; }

$dirlist = array ();

if ($mode != "FILES") { $dirlist[] = $path; }

if ($handle = opendir($path)) {

while (false !== ($file = readdir($handle))) {

if ( $file != '.' && $file != '..' && $file != '') {

$file = $path . $file;

if (!is_dir($file)) {

if ($mode != "DIRS") { $dirlist[] = $file; }

}

elseif ($d >= 0 && $d < $maxdepth) {

$result = searchdir ($file . '/', $maxdepth, $mode, $d + 1);

$dirlist = array_merge($dirlist, $result);

}

}

}

closedir ($handle);

}

if ($d == 0) { natcasesort ($dirlist); }

return ($dirlist);

}



// $dir = '/var/www/html/test/images/arrangements-small';

$dir = 'images/arrangements-small';

$images = searchdir($dir);

foreach($images as $image) {

$image = str_replace('images/arrangements-small/','',$image);

$selected = '';

if ($image == $_POST['image_path']) { $selected = ' selected'; }

print '<option value="' . $image . '"' . $selected . '>' . $image . '</option>';

}

?>

</select>


In essence, this code reads the directory of images available (which my client uploads separately) and then builds the select box based upon the directory list.
Is there a way to incorporate this select box into the new PHPRunner site? Can I replace the select box somehow, through the Onload features possibly?
Thanks!

Sean

J
Jane 11/7/2006

Sean,
you can put this code to the OnLoad event on the Events tab.

Perhaps you'll need to slightly change your code to make it working.