PHP List all files in directory |
PHP List all files in directory |
![]()
Post
#1
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 ![]() |
I was working on a little file upload thing for a website and I'm pretty much done. However, I have a page where I list all files based on the current user. My current script works fine, but it only lists the most recent file uploaded. I'd rather have a full list of all files in the directory instead of the most recent one.
Here's my current script: CODE <?php $directory = $user; if (!is_dir($directory)) { mkdir($directory); $list = '<tr> <td>No files to display.</td> </tr>'; } else { if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $name = ucfirst($file); $list = '<tr> <td>' . $name . '</td> <td><a href="/files/' . $directory . '/?delete=' . $file . '" class="delete">Delete this file</a> <a href="/files/' . $directory . '/?open=' . $file . '">Open this file</a></td> </tr>'; } else { $list = '<tr> <td>No files to display.</td> </tr>'; } } closedir($handle); } echo $list; } ?> It works exactly like I want it to when it comes to listing, but I want to make it so it lists all files as opposed to one. Oh, and, $user is just variable I defined in another script that contains the current user's username. Hilfe? |
|
|
![]() ![]() |