Help with PHP

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

Kadenz

Resistance is FutileEstablished Member
Impact
29
I am try to get a script to detect all the files in a directory, however it only shows the first file in the directory, how can I make so it detects all the files?

This is part of an entire script, but the rest is fine and has no realtion to this.
Here's what I've done:
PHP:
} elseif ($_GET[p] =="4") {
$contentform = '<FORM method="POST" action="index.php?p=sigout">
	<strong>Signature Template:</strong><br>
	<select name=image>';
$handle2 = opendir('templates');
   while (false !== ($image = readdir($handle2))) {
   $image = str_replace('.', '' ,$image);
   $image = str_replace('png', '' ,$image);
   $image = str_replace('indexphp', '', $image);
   $image = str_replace('Thumbsdb', '', $image);
   if ($image != '') {
    $contentform3 = '<option value="'.$image.'.png">'.$image.'</option>';
}
   }
  closedir($handle2);
$contentform2 = '</select>
	<br>
	<P><strong>Font:</strong><br>
	<select name=font>';
$handle = opendir('fonts');
   while (false !== ($font = readdir($handle))) {
   $font = str_replace('.', '' ,$font);
   $font = str_replace('ttf', '' ,$font);
   $font = str_replace('TTF', '' ,$font);
   $font = str_replace('indexphp', '', $font);
   $font = str_replace('Thumbsdb', '', $font);
       if ($font != '') {
    $contentform6 = '<option value="'.$font.'.TTF">'.$font.'</option>';
	} 
	}
   closedir($handle);
$contentform5 = $contentform6.'</select><br>
	<P><strong>Text Line 1:</strong><br>
	<input type="text" name="string" size=35><br>
	<P><strong>Text Line 2:</strong><br>
	<input type="text" name="string2" size=35>
	<P><input type="submit" name="submit" value="Create Image!">
	</FORM><br>';
$page->replace_tags(array(
"{content}" => $contentform.$contentform3.$contentform2.$contentform5
));

Any Help is greatly appreciated
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Instead of
while (false !== ($font = readdir($handle))) {
Try
foreach (readdir($handle) as $font) {
 
0
Close
Doesn't work, it now comes up with nothing.
 
0
Close
your original coding looks ok (I use the same coding on a script I developed. Can you check what the date is of the file that is found, check and see if it is the earliest. If it is it could be that the server database is not updated (remember reading something like that in the manual)
 
0
Close
It works fine in other scripts I made, however it doesn't work in this particular script.
 
0
Close
Maybe replace
while (false !== ($font = readdir($handle))) {
with
while (($font = readdir($handle)) !== false) {
 
0
Close
It makes no difference, still only one showing up. :(
 
0
Close
I just went to PHP.net because I've never done this before and it seems like you have it right..

PHP:
if ($handle = opendir('/path/to/files')) {
   echo "Directory handle: $handle\n";
   echo "Files:\n";

   while (false !== ($file = readdir($handle))) {
       echo "$file\n";
   }

   closedir($handle);

}

That is the correct example.. so I'm not sure why it doesn't work.
 
0
Close
0
Close
try taking out the str_replace lines and see if will then return the ENTIRE content. Possibly these are what are causing the problem.
 
0
Close
No the str_replace is not the problem, it just now shows Thumbsdb for selection not anything else, I think the problem is that I am trying to run PHP within an array, it possible to run it directly like this:

PHP:
$page->replace_tags(array(
"{content}" => echo '<FORM method="POST" action="index.php?p=sigout">
	<strong>Signature Template:</strong><br>
	<select name=image>';
$handle2 = opendir('templates');
   while (false !== ($image = readdir($handle2))) {
   $image = str_replace('.', '' ,$image);
   $image = str_replace('png', '' ,$image);
   $image = str_replace('indexphp', '', $image);
   $image = str_replace('Thumbsdb', '', $image);
   if ($image != '') {
    echo  '<option value="'.$image.'.png">'.$image.'</option>';
}
   }
  closedir($handle2);
echo  '</select>
	<br>
	<P><strong>Font:</strong><br>
	<select name=font>';
$handle = opendir('fonts');
   while (false !== ($font = readdir($handle))) {
   $font = str_replace('.', '' ,$font);
   $font = str_replace('ttf', '' ,$font);
   $font = str_replace('TTF', '' ,$font);
   $font = str_replace('indexphp', '', $font);
   $font = str_replace('Thumbsdb', '', $font);
       if ($font != '') {
    echo '<option value="'.$font.'.TTF">'.$font.'</option>';
	} 
	}
   closedir($handle);
echo '</select><br>
	<P><strong>Text Line 1:</strong><br>
	<input type="text" name="string" size=35><br>
	<P><strong>Text Line 2:</strong><br>
	<input type="text" name="string2" size=35>
	<P><input type="submit" name="submit" value="Create Image!">
	</FORM><br>';
));

or something close to that?
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back