...

View Full Version : Displaying more than one file in a directory..



Errica
12-03-2008, 06:21 AM
This code displays only one file in the directory "_BACKUPS".

How can it be modified to display multiple files?


<td align="center">
<?
$farr=array();
if (file_exists($url_base."_BACKUPS/")) {
$dir= opendir($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>

_Aerospace_Eng_
12-03-2008, 07:06 AM
Thats because you tell it to only list one file.

<td align="center">
<?php
$farr=array();
if (file_exists($url_base."_BACKUPS/")) {
$dir= opendir($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.

Errica
12-03-2008, 08:15 AM
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:


<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/")) {
$dir= opendir($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>

_Aerospace_Eng_
12-03-2008, 06:31 PM
When you submit what are you doing? Are you just redirecting the user to the url or what?

Errica
12-07-2008, 02:27 AM
Hi, yep, it redirects to download.php.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum