Mind_Hunter099 wrote:HI
check this one i dont know what the problem is...........
this code works fine and display all files in a directory to a web page
<?php
chdir('/etc/sound');
$dir = opendir('.');
while($file=readdir($dir)){
echo("$file<BR>");
}
?>
As I recently had a look how to
readdir()
according to the manual instruction for this function
[man]readdir[/man]
while($file=readdir($dir)){
is NOT the way to do it
I hope this is the case for you.
Because then we know the fix is easy.
This is a copy and paste from MANUAL how to use readdir()
<?php
/*
Example 489. List all files in a directory
Please note the fashion in which readdir()'s return value is checked in the examples below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) FALSE since otherwise, any directory entry whose name evaluates to FALSE will stop the loop (e.g. a directory named "0").
*/
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
}
?>
=========================================================
You may also STOP using <?
... because it was a long time since anyone was allowed to use short_open_tag
in the official http://php.net/ PHP MANUAL
For years and years, the php.ini-recommended
has had this note in the php install packages:
; Allow the <? tag.
; Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server.
; For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off
.
And if I recall, this setting as well as a couple of others
will NO LONGER be options in PHP 6
PHP 6 is not far away.
So we all better write code that works with:
short_open_tag = Off
magic_quotes_gpc = Off
register_globals = Off
=============================================
more from
php.ini-recommended:
;;;;;;;;;;;;;;;;;;;
; About this file ;
;;;;;;;;;;;;;;;;;;;
; This is the recommended, PHP 5-style version of the php.ini-dist file. It
; sets some non standard settings, that make PHP more efficient, more secure,
; and encourage cleaner coding.
;
; The price is that with these settings, PHP may be incompatible with some
; applications, and sometimes, more difficult to develop with. Using this
; file is warmly recommended for production sites.
If you intend to only write php code
that will survive and work at some servers today and a few more days
you do not have to bother write good recommended code.
Otherwise you may want to consult
and look what is in pipeline.
There was long long ago people wrote script
that required register_globals ON
... but Things have changed ... ( Bob Dylan quote:!! )
Here you can read more:
Updated 13 days ago: http://cvs.php.net/........./php.ini-recommended
🆒