Edward Posted December 14, 2006 Share Posted December 14, 2006 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 directoryecho '<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! Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/ Share on other sites More sharing options...
obsidian Posted December 14, 2006 Share Posted December 14, 2006 Have you tried defining the absolute path to the folder, or referencing the folder via a relative path, just in case? I'd say try either of these just for fun:[code]<?php$search_dir = './UploadedFiles';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-141113 Share on other sites More sharing options...
Edward Posted December 14, 2006 Author Share Posted December 14, 2006 I have already unfortunately.I've tried:<pre>./UploadedFiles./UploadedFiles/UploadedFilesUploadedFiles//UploadedFiles/UploadedFiles/</pre>Any other ideas? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-141117 Share on other sites More sharing options...
obsidian Posted December 14, 2006 Share Posted December 14, 2006 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 :( Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-141119 Share on other sites More sharing options...
Edward Posted December 19, 2006 Author Share Posted December 19, 2006 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. ??? Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-144384 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 Humour me here and try the full path, but separate by colons, e.g.[code]HD:System Folder:Web Server:Users:UploadedFiles[/code]Where I've put HD, is the disk or volume name.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-144388 Share on other sites More sharing options...
Edward Posted December 29, 2006 Author Share Posted December 29, 2006 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'tPermissions for the subdirectory are rwxr-w-rw Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-149315 Share on other sites More sharing options...
HuggieBear Posted January 2, 2007 Share Posted January 2, 2007 Can you post your most recent version of the code?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-151436 Share on other sites More sharing options...
Edward Posted January 3, 2007 Author Share Posted January 3, 2007 This is the code I'm using:[code]<?phpecho '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 directoryecho '<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 directoryecho '<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. Quote Link to comment https://forums.phpfreaks.com/topic/30635-problems-searching-directories/#findComment-152321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.