jrthor2
01-25-2008, 01:46 PM
I am reading the contents of a directory to get a list of images to show in a dropdown box that uses javascript to show the dropdown. My problem is that I need to have a comma at the end of each line, except the last one, so when I get tot he last image, I don't want a comma at the end. Here is the code.
<?
$folder = opendir("../../../images/tinymce/"); // Use 'opendir(".")' if the PHP file is in the same folder as your images. Or set a relative path 'opendir("../path/to/folder")'.
$pic_types = array("jpg", "jpeg", "gif", "png");
$index = array();
list($width, $height, $type, $attr) = @getimagesize($image);
while ($file = readdir ($folder)) {
if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types)) {
array_push($index,$file);
}
}
closedir($folder);
$value = array_values($index);
?>
var tinyMCEImageList = new Array(
<?
foreach($value as $image_file) {
?>
["<?=image_file;?>","<?=print '/~zluthorg/images/tinymce/'.image_file?>"],
<? } ?>
);
thanks
<?
$folder = opendir("../../../images/tinymce/"); // Use 'opendir(".")' if the PHP file is in the same folder as your images. Or set a relative path 'opendir("../path/to/folder")'.
$pic_types = array("jpg", "jpeg", "gif", "png");
$index = array();
list($width, $height, $type, $attr) = @getimagesize($image);
while ($file = readdir ($folder)) {
if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types)) {
array_push($index,$file);
}
}
closedir($folder);
$value = array_values($index);
?>
var tinyMCEImageList = new Array(
<?
foreach($value as $image_file) {
?>
["<?=image_file;?>","<?=print '/~zluthorg/images/tinymce/'.image_file?>"],
<? } ?>
);
thanks