Jump to content

Problems Searching Directories


Edward

Recommended Posts

Hi,

I'm trying to build a basic site to store files. I'm currently working on a directory search using the code below. If i place by 'browse.php' doc in the root directory it works fine, if I place it in a subfolder (such as 'UploadedFiles) then it works fine, however if I keep the doc in the root folder and try to search a subfolder (such as Uploaded Files), then it finds nothing. I'm using Apache on Mac OSX. All files/folders have my ownership, and everyone else can also read and write them.

[code]
<?php
// set the directory name and open it

$search_dir = '.'; // fullstop represents the current directory and works! if I use 'UploadedFiles' INSTEAD then it doesn't work?!?!

//$search_dir = 'UploadedFiles';
$dp = opendir ($search_dir);

// now list the directories of this directory

echo '<p>Directories:</p>';
while ($item = readdir ($dp) ) {
if ( (is_dir ($item)) AND (substr ($item, 0, 1) != '.') ) {
echo "$item<br />";
}
}
rewinddir ($dp);

echo '<p>Files:</p>';

echo '<p><table cellpadding="5"><tr>';
echo '<td>File Name</td>';
echo '<td>File Size</td>';
echo '<td>Last Modified</td>';
echo '</tr>';

while ($item = readdir ($dp) ) {
if ( (is_file ($item)) AND (substr ($item, 0, 1) != '.') ) {
$fs = filesize ($item);
$lm = date('F j, Y', filemtime ($item)); //RESOLVE!!!!
//$lm = filetime ($item); //RESOLVE!!!!
echo "<tr><td>$item</td><td>$fs bytes</td><td>$lm</td></tr>";
}
}

echo '</table>';
closedir ($dp);
?>
[/code]

Help would be great!
Link to comment
Share on other sites

I'm coming up blank. The only things I can think of are:

1) Double check your spelling and capitalization. Unix based systems are case sensitive.
2) Double check your permissions. '777' on the folder to be updated specifically. Even though the files or folders have your ownership, it's the server user (usually 'apache') that's trying to write to the folder, and unless they're part of your ownership group, sometimes that can cause an error.

I know you already said that all folders had open permissions, but I figured I'd just throw in that little piece of advice... otherwise, I'm stumped :(
Link to comment
Share on other sites

I've checked spelling over and over and unfortunately that's not it. I'm using OSX to change the permissions (via 'Get Info). I've tried changing owndership and group, always allowing everyone to read and write the files/directories but still nothing. Thanks for your help so far but any other ideas would be great, I've come to a complete standstill on this project.  ???
Link to comment
Share on other sites

  • 2 weeks later...
It was definitely worth a try but I can't get that to work, the path doesn't seem right. These are the path's I'm trying to search the current folder:

$directory01 = '.'; // This works!
$directory02 = './'; // This works!
$directory03 = '/Users/edward/Sites/BeatProgress/Clients/002_Sholl/Storage'; // This works!
$directory04 = '/Users/edward/Sites/BeatProgress/Clients/002_Sholl/Storage/files'; // This doesn't work?!
$directory05 = 'Macintosh HD:Users:edward:Sites:BeatProgress:Clients:002_Sholl:Storage'; // This doesn't work - it thinks I'm entering a relative subfolder, how do I get around this?

I'm using OSX and running this site from my personal Sites folder. Please help, it must be possible!

PS I've also tried on hosted webspace and I have similar problems, I can search the current directory but not a specified subdirectory:
/home/user/public_html/sholl/storage/ // this works
/home/user/public_html/sholl/storage/uploaded_files/ // this doesn't
Permissions for the subdirectory are rwxr-w-rw
Link to comment
Share on other sites

This is the code I'm using:

[code]
<?php

echo 'You are here: '.getcwd();

$directory01 = '.';

$directory02 = 'Files';

echo '<p><a href="'.$directory01.'">'.$directory01.'</a></p>';

echo '<p><a href="'.$directory02.'">'.$directory02.'</a></p>';

echo '<hr />';

// set the directory name and open it

$search_dir = "$directory01"; // fullstop represents the current directory

$dp = opendir ($search_dir);

// now list the directories of this directory

echo '<p>Directories in '.$search_dir.'</p>';

while ($item = readdir ($dp) ) {

if ( (is_dir ($item)) AND (substr ($item, 0, 1) != '.') ) {

echo "$item<br />";

}

}

rewinddir ($dp);

echo '<p>Files:</p>';

echo '<p><table cellpadding="5"><tr>';
echo '<td>File Name</td>';
echo '<td>File Size</td>';
echo '<td>Last Modified</td>';
echo '<td>File Owner</td>';
echo '<td>File Permissions</td>';
echo '</tr>';

while ($item = readdir ($dp) ) {

if ( (is_file ($item)) AND (substr ($item, 0, 1) != '.') ) {

$fs = filesize ($item);
$lm = date('F j, Y', filemtime ($item)); //RESOLVE!!!!
//$lm = filetime ($item); //RESOLVE!!!!
echo "<tr><td>$item</td><td>$fs bytes</td><td>$lm</td><td>".fileowner($item).'</td><td>'.fileperms($item).'</td></tr>';
}

}

echo '</table>';

closedir ($dp);

echo '<hr />';

// set the directory name and open it

$search_dir = "$directory02"; // fullstop represents the current directory

$dp = opendir ($search_dir);

// now list the directories of this directory

echo '<p>Directories in '.$search_dir.'</p>';

while ($item = readdir ($dp) ) {

if ( (is_dir ($item)) AND (substr ($item, 0, 1) != '.') ) {

echo "$item<br />";

}

}

rewinddir ($dp);

echo '<p>Files:</p>';

echo '<p><table cellpadding="5"><tr>';
echo '<td>File Name</td>';
echo '<td>File Size</td>';
echo '<td>Last Modified</td>';
echo '</tr>';

while ($item = readdir ($dp) ) {

if ( (is_file ($item)) AND (substr ($item, 0, 1) != '.') ) {

$fs = filesize ($item);
$lm = date('F j, Y', filemtime ($item)); //RESOLVE!!!!
//$lm = filetime ($item); //RESOLVE!!!!
echo "<tr><td>$item</td><td>$fs bytes</td><td>$lm</td></tr>";
}

}

echo '</table>';

closedir ($dp);

?>
[/code]

Directory01 works, directory02 doesn't.


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.