Welcome! Log In Create A New Profile

Advanced

Topic 3B

Posted by Anonymous User 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Re: Topic 3B
March 22, 2006 11:46AM
I still cannot open a folder that is displayed in the list. The fact that it is displayed in the list indicates that the folder does exist

/studentPHP/directory_navigator.php?%20dir=./Test

where in the code is the URL as indicated above determined, the ?%20dir=./Test does not seem correct, but if I change it manualy to
/studentPHP/directory_navigator.php/Test then I get the The page cannot be found

I am a little confused

I notice that the list starts with a /
this tells me that one of the loops is not correct but I do not get it
/
Network/
Test/
addrecord_form.php
array.php
book.html
bookform.php
color.php
etc



my code is


<?php
/* this script creates a directory navigation script that allows users to view the contents
of a directory as well as the contents of the files within the directory*/

if(!$dir)
$dir = ("./"winking smiley;
$dp = opendir($dir);

echo "<table border ='0' width = '100%' cellspacing = '0' cellpadding = '0'>\n";
while($filenames[] = readdir($dp));

sort($filenames);
for($i = 0; $i < count($filenames); $i++)
{
$item = $filenames[$i];

if (is_dir($item))
{
if($item != '.' && $item != '..'winking smiley

echo "<tr><td width = '100%'><a href='$PHP_SELF? dir=$dir$item'>$item/</a></td></tr>\n";
}

else
echo "<tr><td width='100%'><a href='$dir/$item'>$item</a></td></tr>\n";
}
?>
</table>
avatar
Mac
Re: Topic 3B
March 22, 2006 12:36PM
/studentPHP/directory_navigator.php/Test ?

do you mean

/studentPHP/Test/directory_navigator.php?


This script does not cater for jumping between directories - it only allows you to navigate within a directory.

the / on top comes from this line:

echo "<tr><td width = '100%'><a href='$PHP_SELF? dir=$dir$item'>$item/</a></td></tr>\n";

You're quite correct to assume an extra loop since clearly no $item will leave you with just the / being echoed, which is what is happening here.

let's do dome error checking ourselves:
If you add
$how_many=count($filenames);
echo "$how_many";

This will show e.g. 13. I have only 10 files in this directory.
While I think it was meant as a rude attempt at showing you to "be in the root directory".


Try this code and read it.













Re: Topic 3B
March 22, 2006 03:39PM
OK now it is as clear as mud

on page 39 of masterskill para 5 indictes to save the file in the studentPHP directory, which is where it is on my PC. not in root


on page 40 of masterskill para 7 indicates that I shoudl be able to open any folder that is on the list

then to make matters worse
when I add the
$how_many=count($filenames);
echo "$how_many";

it counts 33 but there are only 32 files and 2 folders together in this folder on my PC (counting all the files in the sub directories also)
avatar
Mac
Re: Topic 3B
March 22, 2006 03:59PM
Oops - some code I've posted was after 'Try this code and read it' was not posted here above.

Change the $i=0; to $i=1, then you will have the exact number of files. Root, by definition, is c:\foxserv\www

Here, "root" refers to the directory your file is in, i.e. /studentPHP
Re: Topic 3B
March 23, 2006 08:29AM
OK well
PHP still cannot count, I still get 33 files
I checked my counting and M Soft agrees with me only 32 files.

I still cannot open a folder, which is inside the studentPHP folder
Re: Topic 3B
March 27, 2006 10:27AM
Can anyone help? I keep getting the following error with the directory navigator script:
Parse error: parse error, unexpected '}', expecting ',' or ';' in C:\foxserv\www\studentphp\directory_navigator.php on line 14
and I can't see my error ...

<?php
if (!$dir)
$dir=("./"winking smiley;
$dp=opendir($dir);
echo "<table border='0' width='100%' cellspacing='0' cellpadding='0'>\n";
while ($filenames[]=readdir($dp));
sort ($filenames);
for($i = 0; $i < count($filenames); $i++) {
$item=$filenames[$i];
if(is_dir($item))
{
if($item !='.' && $item !='..'winking smiley
echo "<tr><td width='100%'><a href='$PHP_SELF? dir=$dir$item'>$item/</a></td></tr>\n;"
}

else
echo "<tr><td width='100%'><a href='$dir/$item'>$item</a></td></tr>\n";
}
?>
</table>
Re: Topic 3B
March 27, 2006 11:38AM
All done.
Re: Topic 3B
March 27, 2006 11:40AM
check your {} open and close. And also the while statement. Also you have a ; at the wrong place.
Re: Topic 3B
March 27, 2006 11:55AM
my problem is that I have checked my opening and closing brackets and semi-colons both against the book and aginst what makes sense to me and I can't see the error ...
Re: Topic 3B
March 27, 2006 01:23PM
Everything's good here smiling smiley
Sorry, you do not have permission to post/reply in this forum.