Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Displaying more than one file in a directory..

    This code displays only one file in the directory "_BACKUPS".

    How can it be modified to display multiple files?

    PHP Code:
    <td align="center"> 
        <?
         $farr
    =array();
         if (
    file_exists($url_base."_BACKUPS/")) {
            
    $diropendir($url_base."_BACKUPS/"); 
            
    $fl readdir($dir);
            while (
    $fl readdir ($dir)) { 
               if (
    $fl != "." && $fl != ".." &&  (eregi("\.gz",$fl))){ 
                  
    $farr[]=$fl;
               }
            } 
            
    closedir($dir); 
         }
         if (empty(
    $farr)) $farr[0]="No backup found"
        
    ?>              
          File to download:  
          <input name="zipname" type="hidden" value="<?=$farr[0];?>" >
    <?=$farr[0];?>
        </td>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Thats because you tell it to only list one file.
    PHP Code:
    <td align="center"> 
        <?php
         $farr
    =array();
         if (
    file_exists($url_base."_BACKUPS/")) {
            
    $diropendir($url_base."_BACKUPS/"); 
            
    $fl readdir($dir);
            while (
    $fl readdir ($dir)) { 
               if (
    $fl != "." && $fl != ".." &&  (eregi("\.gz",$fl))){ 
                  
    $farr[]=$fl;
               }
            } 
            
    closedir($dir); 
         }
    sort($farr);
         if (
    sizeof($farr) == 0
    {
        
    ?> 
    <p>No backup found  </p>
    <?php
    }
    else
    {
    $i 0;
    foreach(
    $farr as $file)
    {
    ?>
          File to download:  
          <input name="zipname<?php echo $i?>" type="hidden" value="<?php echo $file?>"><br>
    <?php
    $i
    ++;
    }
    ?>
    </td>
    You could also use zipname[] for the name of the inputs and remove the $i part you will just need to learn how to read through an array of inputs.
    That should work.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    I inadvertently left out a necessary part of the code...a huge oversight on my part, I apologize! I can't figure out how to implement the submit (Go) button for each:

    PHP Code:
    <table align="center" bgcolor="#8BA5C5" border="0" cellpadding="4" cellspacing="0" width="760">
      <form name="dodownload" method="post" action="download.php">
      <tr> 
        <td align="center"><strong>Download Backup</strong></td>
      </tr>
      <tr> 
        <td align="center"> 
        <?php
         $farr
    =array();
         if (
    file_exists($url_base."_BACKUPS/")) {
            
    $diropendir($url_base."_BACKUPS/"); 
            
    $fl readdir($dir);
            while (
    $fl readdir ($dir)) { 
               if (
    $fl != "." && $fl != ".." &&  (eregi("\.gz",$fl))){ 
                  
    $farr[]=$fl;
               }
            } 
            
    closedir($dir); 
         }
    sort($farr);
         if (
    sizeof($farr) == 0
    {
        
    ?> 
    <p>No backup found  </p>
    <?php
    }
    else
    {
    $i 0;
    foreach(
    $farr as $file)
    {
    ?>
          File to download:  
          <input name="zipname<?php echo $i?>" type="text" value="<?php echo $file?>"><br>
    <?php
    }
    $i++;
    }
    ?>
    </td>
      </tr>
      <tr> 
        <td align="center">
          <input type="hidden" name="path" value="<?=$url_base;?>">
          <input name="send4" type="submit" class="textbox" value="Go">
        </td>
      </tr>
      </form>
    </table>

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    When you submit what are you doing? Are you just redirecting the user to the url or what?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Errica (12-07-2008)

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Posts
    252
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Hi, yep, it redirects to download.php.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •