Log In · Register

 
PHP List all files in directory
Mikeplyts
post Aug 28 2010, 10:51 AM
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?
 

Posts in this topic
Mikeplyts   PHP List all files in directory   Aug 28 2010, 10:51 AM
ahmad   CODEwhile (false !== ($file = readdir(...   Aug 28 2010, 06:38 PM
Mikeplyts   Oh, okay. Thanks man, worked great!   Aug 29 2010, 05:19 AM
manny-the-dino   Topic Closed and Moved   Aug 30 2010, 04:06 PM


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: