Domanda

I am trying to construct my own file directory but I have been stuck on one part for a day and cant figure out how to approach this. When the code below runs i checks if its a file or a directory what i want to achieve is when the code detects thats its a directory when clicked on Open Folder it opens the folder with the list of files that it contains can anyone help me here and give me some kind of idea how to approach this ?

echo'<table style="background-color: beige; padding: 10px; border: 1px dashed #999;">';
echo'<tr>
<th>File Name</th>
<th colspan="3">Action</th>
</tr>';
foreach(glob('language/*') as $filename){
if ($filename != 'connect.php' && $filename != 'edit.php' && $filename != 'index.php' && $filename != 'nbproject'){
if(is_file($filename)){
echo'<tr>
<td>'.$filename.'</td>
<td><a href="'.$filename.'" name="ru">RU</a></td>
<td><a href="'.$filename.'" name="eng">ENG</a></td>
<td><a href="'.$filename.'" name="lt">LT</a></td>
</tr>';
var_dump($filename);
}
else if(is_dir($filename)){
echo '<tr>
<td>'.$filename.'</td>
<td colspan="3"><a href="'.$filename .'" name="open" >Open Folder</a><td>
</tr>';
}
}
}
echo'</table>';

I am thinking i can achieve this with opendir function or glob function am I on the right track ? tnx for the help.

P.S. One more question I am using glob to read my directory is readdir better to achieve this or is there no difference ? And feel free to point out any other flaws in my code :)

È stato utile?

Soluzione

You don't need the form tag. You should pass a variable containing the folder name directly from the href property of a tags. e.g.

<a href="myscript.php?folder=<?php echo $foldername ?>"><?php echo $foldername ?></a>

Be sure to properly check that the directory the user is trying to open is safe to access or you will have nasty security consequences.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top