DeathStar Posted March 20, 2007 Share Posted March 20, 2007 Hi I want to make a script that will show all the files in the folder and then list them with a link to edit them in the script(liek put the file in a textarea). Anyone know how to do this? Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/ Share on other sites More sharing options...
per1os Posted March 20, 2007 Share Posted March 20, 2007 http://us2.php.net/manual/en/class.dir.php http://us2.php.net/manual/en/ref.dir.php Should serve you right. Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-211600 Share on other sites More sharing options...
DeathStar Posted March 20, 2007 Author Share Posted March 20, 2007 That works: Handle: Resource id #2 Path: /home/deathstar/www/ . .. phpmyadmin index.php But what i realy wanted is so that i can detirmine if its a folder display an image(icon) and vise versa with php files and html... Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-211622 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 You should be able to get the same result from that, you just have to go into the next directory and check for image files or php files. If there is a .jpg or .gif extension than use this image if not and there is .php use this image. The problem arises when you have a .php in an image directory, which one to display??? =) Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-211683 Share on other sites More sharing options...
Barand Posted March 21, 2007 Share Posted March 21, 2007 http://www.php.net/is_dir will tell you if it's a folder http://www.php.net/strrchr to get the extension <?php $file = 'xyz.php'; $ext = strrchr($file, '.'); echo $ext; //--> .php ?> Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-211689 Share on other sites More sharing options...
DeathStar Posted March 21, 2007 Author Share Posted March 21, 2007 Ok i got that part but failing miserably! Here is my script: <?php $dict = $_SERVER['DOCUMENT_ROOT']; $d = dir($dict); echo "Path to this dictinary: " . $d->path . "<br />"; while (false !== ($entry = $d->read())) { $ext = strrchr($entry, ''); if ($ext == ""){ echo "<font color=red>$ext$entry</font>";} elseif ($ext == "php"){ echo "<font color=green>$ext$entry</font>";} elseif ($ext == "html"){ echo "<font color=blue>$ext$entry</font>";} elseif ($ext == "txt"){ echo "<font color=yellow>$ext$entry</font>";} else{ echo "$ext$entry<br />";} } $d->close(); ?> Any help? There is more than one result so it must be on seprate line! Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-212361 Share on other sites More sharing options...
Barand Posted March 21, 2007 Share Posted March 21, 2007 You left out the "."s $ext = strrchr($entry, '.'); elseif ($ext == ".php"){ Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-212387 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 ok thanks. But the result im getting is: Path to this dictinary: /home/deathsta/public_html .. ... .PNGeditor.PNG .phpbuton1.php.phpglobal_func.php.phpmenu.phpds1.phpstaff.php.shtml404.shtml proxys.phpinex.php.phphead.phpe107ds.phpviemember.php.phplogin.phpformcgi-binds2profilesiteb.phpbuton.php.exeDeathStarviewer.exe .htaccess.htaccess and not on seperate liness Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-212601 Share on other sites More sharing options...
Barand Posted March 22, 2007 Share Posted March 22, 2007 If you echo "$ext$entry" then you get exactly that. ie ".PHPmyfile.PHP" Add br tags to get new lines Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-212616 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 and remove $ext.. Now i get it right but for link's i dont ?!? <?php $dict = $_SERVER['DOCUMENT_ROOT']; $d = dir($dict); echo "Path to this dictinary: " . $d->path . "<br />"; while (false !== ($entry = $d->read())) { $ext = strrchr($entry, "."); if ($ext == ""){ echo " <style> ahref1. { a:link {color: red; }; } ahref2. { a:link {color: green; }; } ahref3. { a:link {color: blue; }; } ahref4. { a:link {color: yellow; }; } ahref5. { a:link {color: black; }; } </style> "; echo "<br><a href='$entry' class='ahref1'>$entry</a>";} elseif ($ext == ".php"){ echo "<br><a href='$entry' class='ahref2'>$entry</a>";} elseif ($ext == ".html"){ echo "<br><a href='$entry' class='ahref3'>$entry</a>";} elseif ($ext == ".txt"){ echo "<br><a href='$entry' class='ahref4'>$entry</a>";} else{ echo "<br><a href='$entry' class='ahref5'>$entry</a>";} } $d->close(); ?> Realy cannot understand this ??? Link to comment https://forums.phpfreaks.com/topic/43567-index-listingi-think/#findComment-212686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.