I have the following code:
$dir="video";
$dh = opendir($dir);
while($file = readdir($dh)){
if ($file!="." && $file!=".."){
echo "<li><a href=list_video.php?dir=$file>$file</a></li><br>";
}
}
It works very well , but if the filename contains spaces within it (example: "tra la la") then the function reads the only a part of the filename , untill it encounters the first space (example: $file = "tra" if it were to be "tra la la".
Are there any solutions to read the whole filename even if it has spaces within it?
Thank You
Why does readdir() read the filename in string till space???
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Why does readdir() read the filename in string till space???
readdir() is reading filenames just fine. If you look at the source of your page you will see that the filenames are complete. One problem is that you dont have quotes around the href atrribute value, and second you need to urlencode your filenames.
Try this
Try this
Code: Select all
echo "<li><a href=\"list_video.php?dir=" . urlencode($file) . "\">{$file}</a></li><br>";