Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-10-2009
Member
 
Join Date: Aug 2009
Posts: 59
How to display a listbox inside a directory

Here is my problem. I have a form of update, and would like to display the names of the images contained in a folder all in a listbox. That way I could select the image I want through the listbox and do a little update. But as my knowledge is concerned, php is quite limited (sql insert, update and delete). So how can I display a listbox inside a directory?

PHP Code:
<select name="listDir">
<?php
$rep 
='upload/';
if (!
is_dir ($rep)) {
    echo 
'Error, '$dir,' is not a valid directory';
    exit;
}
$dir opendir ($rep);
        while (
false !== ($file readdir ($dir))) {
            if (
$file !== '..' && $file !== '.') {
                echo 
'<option value="',$file,'">',$file,'</option>';
            }
        }
?>
</select>
Reply With Quote
  #2  
Old 15-10-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to display a listbox inside a directory

Tries more or less it, I do not know if it will work the first time, trying to understand/debug (no wizard in there) and if something is wrong does not hesitate to ask further questions:

PHP Code:
<select name="image">
<?php
$d 
dir("/myaccount/whichcontains/theimages" );
while (
false !== ($entry $d->read()))
{
   if (
'.' !== $entry && '..' != $entry)
   {
   
?>
      <option value="<?php echo $entry?>"><?php echo $entry?></option>
   <?php
   
}
}
$d->close();
?>
</select>
Reply With Quote
  #3  
Old 15-10-2009
Member
 
Join Date: Aug 2009
Posts: 59
Re: How to display a listbox inside a directory

If so, its the penalty, beginning before the huge eternal great php, I look and try to understand, but it is not working or I think I missed something. I need little more explanation on this.
Reply With Quote
  #4  
Old 15-10-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to display a listbox inside a directory

The method I gave you does the same thing that you have found, but object-oriented.

Instead of using opendir () which returns you $dir, use readdir() on it and end closedir(), you use the dir() which returns you an object of type Directory.

Then you use the object methods directly.

PHP Code:
$dir opendir($rep); 
$entry readdir($rep); 
closedir($rep);

$d dir($rep); 
$entry $d->read();
$d->close(); 
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to display a listbox inside a directory"
Thread Thread Starter Forum Replies Last Post
How to clean black spots or dust inside the iMac 27inch display Rwanda Portable Devices 2 28-05-2012 12:33 PM
How to create ListBox in VB.net? MarceloQuad Software Development 4 22-01-2010 08:44 PM
C# Listbox control abhinavm Software Development 2 07-08-2009 11:01 PM
Active Directory Migration Tool User Migration Renaming Display nameTarget Domain djlanza@gmail.com Active Directory 3 01-07-2009 03:46 PM
To display webpage inside another webpage Faakhir Technology & Internet 3 24-03-2009 10:59 AM


All times are GMT +5.5. The time now is 10:27 AM.