DaveRandom Posted February 24, 2009 Share Posted February 24, 2009 Hi First thing to say is a complete PHP beginner, so please assume I know nothing in any answers (I know a bit but very patchy and widely ranged) I have this script to list all the files of a given directory on a page (mostly borrowed code). <?php $path = "uploads"; $dir_handle = @opendir($path) or die("Unable to open $path"); echo "Directory Listing of <i><b>$path</b></i><br><br>"; while ($file = readdir($dir_handle)) { if($file!="." && $file!="..") echo "<a href='uploads/$file'>$file</a><br>"; } closedir($dir_handle); ?> I am trying to work urlencode in so the link path is encoded but the text displayed on the link is not affected. I have been trying various ways to create another variable (I've been calling it $filelink) and manipulate that into an encoded version of $file. However, I can't seem to come up with anything other than infinite circles in the while loop, resulting in nothing else happening on the page after the script. Please help! Link to comment https://forums.phpfreaks.com/topic/146743-solved-how-to-implement-urlencode-in-directory-listing-script/ Share on other sites More sharing options...
DaveRandom Posted February 25, 2009 Author Share Posted February 25, 2009 Sorted. while ($file = readdir($dir_handle)) { if($file!="." && $file!="..") echo "<a href='uploads/". urlencode ($file)."'>$file</a><br>"; } Also should really be using rawurlencode to be fully standards compliant. Link to comment https://forums.phpfreaks.com/topic/146743-solved-how-to-implement-urlencode-in-directory-listing-script/#findComment-770667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.