KILOGRAM Posted March 11, 2008 Share Posted March 11, 2008 i need a help regarding the following code pasted below. <?php function dirList ($directory) { $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $results[] = $file; dirList($directory); } } closedir($handler); return $results; } $results=$_POST['results']; $dir = "c:\php"; $files = dirList($dir); foreach ($files as $file) { echo "<a href=\"$file\" title=\"$file\">$file</a><br />"; } ?> the above code is fine in displaying the files and folders but when i am trying to click the any of the files and folders iam not able to open the file and folders. can any one modify the above code and please reply to me .it sjould have access to open the file or folder when clicked to the path provided by us. Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/ Share on other sites More sharing options...
frijole Posted March 11, 2008 Share Posted March 11, 2008 <?php function dirList ($directory) { $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $results[] = $file; dirList($directory); } } closedir($handler); return $results; } $results=$_POST['results']; $dir = "c:\php"; $files = dirList($dir); foreach ($files as $file) { echo "<a href=\"$file\" title=\"$file\">$file[/url] "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489120 Share on other sites More sharing options...
KILOGRAM Posted March 11, 2008 Author Share Posted March 11, 2008 but this is the same code that i had posted Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489365 Share on other sites More sharing options...
skidz Posted March 11, 2008 Share Posted March 11, 2008 <?php function dirList ($directory) { $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $results[] = $file; dirList($directory); } } closedir($handler); return $results; } $results=$_POST['results']; $dir = "c:\php"; $files = dirList($dir); foreach ($files as $file) { echo "<a href=\"$file\" title=\"$file\">$file[/url]</a>"; } ?> no closing <a> tag Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489378 Share on other sites More sharing options...
KILOGRAM Posted March 11, 2008 Author Share Posted March 11, 2008 but it does not link me to open the files in any folder.wheni clicked the file it is not openening Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489401 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 no closing <a> tag infact their was but the forum converted it to [/url] as it wasn't posted in a code tag, the reason you can't open the file is because you need link to them via the web link not the file link i guess you could do this <?php function dirList ($directory, $startpath) { $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $nextDir = $directory."/".$file; $results[] = preg_replace('%^'.preg_quote($startpath).'/%', '', $nextDir); if(is_dir($nextDir)) { $results = $results + dirList($nextDir, $startpath); } } } closedir($handler); return $results; } $results=$_POST['results']; $dir = dirname(__FILE__);//"c:\php"; $files = dirList($dir, $dir); foreach ($files as $file) { echo "<a href=\"$file\" title=\"$file\">$file</a><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489403 Share on other sites More sharing options...
KILOGRAM Posted March 11, 2008 Author Share Posted March 11, 2008 but still it say s unable to open the path Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489406 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 seams to work on my pc.. when you hover over a link.. whats the path? Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489408 Share on other sites More sharing options...
KILOGRAM Posted March 11, 2008 Author Share Posted March 11, 2008 c:\php Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489411 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 Can you post the code you have.. as it should start http:// Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489417 Share on other sites More sharing options...
KILOGRAM Posted March 11, 2008 Author Share Posted March 11, 2008 I didnt get what u told, but I am sending the exact code which i am using for executing. The problem it is showing all files in c:\, and more over I am not able to access them. <?php function dirList ($directory, $startpath) { $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $nextDir = $directory."/".$file; $results[] = preg_replace('%^'.preg_quote($startpath).'/%', '', $nextDir); if(is_dir($nextDir)) { $results = $results + dirList($nextDir, $startpath); } } } closedir($handler); return $results; } $results=$_POST['results']; $dir = dirname(""c:\php");//"c:\php"; $files = dirList($dir, $dir); foreach ($files as $file) { echo "<a href=\"$file\" title=\"$file\">$file</a><br>"; } ?> Please make requried modifiction.I am new to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/95537-need-help-get-function/#findComment-489564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.