Php query

Soldato
Joined
24 Nov 2002
Posts
16,378
Location
38.744281°N 104.846806°W
I have :

Code:
<form name="goit">
<select name="select" onChange="preview();">
<option selected value="white.gif"></option>

<? 
$dir_handle = @opendir('../pics'); 
	if ( !$sort ){
	while ($file = readdir($dir_handle)) { 
	if ($file != '.htaccess' && $file != '.' && $file != '..' && $file != 'index.php' && $file != 'template.php' && $file != 'white.gif'){
    echo "<option value=\"$file\">$imagenoe</option>";
	}
} 
}
closedir($dir_handle);
echo "</select>";
echo "<br><br><img src=\"white.gif\" name=\"pic\" id=\"pic\">";
$imageoe  = str_replace (".","", strrchr ($file,"."));
?>

To display all the pictures in a directory. However, i want to do two things to this,

1 - make it work. For some reason, the $imagenoe doesn't work, I've tried to strip the extension and just display the file name - but it hasn't worked.

2 - There are thumbnails in the dir which have the format file.thumb.extension, I would like those to not be displayed.


Also, I have:

Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function preview() {
if (document.goit.select.value == "white.gif") {
  document.pic.src = + document.goit.select.value;
} else {
  document.pic.src = "../pics/" + <?php echo $imageoe ?> + ".thumb" + <?php echo $extension ?> +;
} 
}
</script>

To display the picture on change and sort the dirs out. However, I don't know how to make "$extension" display the extension. Perahps using $ext = strrchr($file, "."); ?

Can you guys see what I'm trying to do?

I'm trying to have a drop down box that display all the images in a dir. However, I want the "value" of the box to be the TRUE filename + extension of the large image, however, I wan the picture displayed the thumbnail version.

The reason i want the true filename displayed (1.jpg not the thumbmail pic: 1.thumb.jpg) as as I want to give the option (passworded) of delete the image AND its associated thumbnail file.
 
Last edited:
Berserker said:
Code:
$imageoe = preg_replace('/\.[^.]*$/', '', $file);
Will sort out the file extensions for you.

Edited for an improved version.

May come back later for some more. :)
I have used:

$file1 = preg_replace('/\.[^.]*$/', '', $file);

This is fine, it has stripped the .jpg off, however, I have some "blah.jpg.thumb.jpg" This has stripped the jpg off the end... not all of the ....'s.

Basically, I would like do simply ONLY display files that end with .thumb.jpg. However, I want to display the thumb when the main image is selected.

Imagine three pics, 1.jpg, 2.jpg and 3.jpg and the appropraite thumbs, 1.jpg.thumb.jpg, 2.jpg.thumb.jpg and 3.jpg.thumb.jpg. I want to display only "1", "2" and "3" in the select box, however, I want the value to be "1.jpg" BUT the preview pic to be 1.jpg.thumb.jpg. Also, I want to be able to press a delete link, under the 1.jpg.thumb.jpg image, but make it delete both 1.jpg.thumb.jpg and 1.jpg.

That make sense?
 
Back
Top Bottom