Welcome! Log In Create A New Profile

Advanced

TASK 3B-2

Posted by sandile 
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
TASK 3B-2
July 31, 2007 04:39PM
Completed!!!!
Re: TASK 3B-2
August 12, 2007 05:36PM
3B-2 Directory Navigation Script

The test directory link does not open. Any idea what I'm missing in the code?
Re: TASK 3B-2
August 13, 2007 05:43PM
Try using @extract($_GET); or $dir = $_GET['dir'];

The <a href='?dir=./Test'> means that you are passing the $dir variable via the url hence the need to use @extract($_GET) ????? Hope this is the right explaination.
Anonymous User
Re: TASK 3B-2
August 13, 2007 07:47PM
Task 3B-2 completed!!
Re: TASK 3B-2
August 13, 2007 09:00PM
Task 3B-2 completed.
Re: TASK 3B-2
August 14, 2007 05:07PM
Task 3B-2 Completed!!!
Re: TASK 3B-2
August 14, 2007 05:32PM
@extract($_GET); does the trick. Task now complete. Tanx Sandile
avatar
Mac
Re: TASK 3B-2
August 17, 2007 12:59PM
With older versions of PHP, if you created a form with a field name of say "name", PHP would automatically have created a variable "$name" on the next page. Same if you did send it through the URL. Not anymore.

So you have to "fecth" the variable now, using $_POST or $_GET. But you have to do that with each one. @extract automatically extracts all at once. Which is nice.

Remember, you can link back to many previous forums (2006 forums on top of forum list) for a wealth of information. We use the same manual each semester so your questions may already have been answered elsewhere.
Re: TASK 3B-2
August 17, 2007 01:52PM
looks like i am on track. i have caught up and am on schedual. Sweet
Re: TASK 3B-2
August 23, 2007 11:37AM
Task completed....
Re: TASK 3B-2
August 27, 2007 08:20AM
Task 3B-2 Completed
Re: TASK 3B-2
August 29, 2007 07:07AM
3B-2 finished.

Quick Q Mac: confused smiley
The php code for this task only opens a set directory and then makes
url's for all the items found in that directory...
Is it possible that that you can open a directory urself and browse to
find a specific item?

Hope my q is clear enough..
Re: TASK 3B-2
August 30, 2007 12:52AM
/* i think this is maybe what you are looking for. i wish i wrote this... smiling smiley
but i have to give the credit to the guys that post over at php.net this isnt
the prittiest of code but it is rather late... njoy*/

<?php
// show directory content
function showDir($dir, $i, $maxDepth){
$i++;
if($checkDir = opendir($dir)){
$cDir = 0;
$cFile = 0;
// check all files in $dir, add to array listDir or listFile
while($file = readdir($checkDir)){
if($file != "." && $file != ".."winking smiley{
if(is_dir($dir . "/" . $file)){
$listDir[$cDir] = $file;
$cDir++;
}
else{
$listFile[$cFile] = $file;
$cFile++;
}
}
}

// show directories
if(count($listDir) > 0){
sort($listDir);
for($j = 0; $j < count($listDir); $j++){
echo "
<tr>";
$spacer = "";
for($l = 0; $l < $i; $l++) $spacer .= "&emsp;";
// create link
$link = "<a href=\"" . $_SERVER["PHP_SELF"] . "?dir=" . $dir . "/" . $listDir[$j] . "\">$listDir[$j]</a>";
echo "<td>" . $spacer . $link . "</td>
</tr>";
// list all subdirectories up to maxDepth
if($i < $maxDepth) showDir($dir . "/" . $listDir[$j], $i, $maxDepth);
}
}

// show files
if(count($listFile) > 0){
sort($listFile);
for($k = 0; $k < count($listFile); $k++){
$spacer = "";
for($l = 0; $l < $i; $l++) $spacer .= "&emsp;";
echo "
<tr>
<td>" . $spacer . $listFile[$k] . "</td>
</tr>";
}
}
closedir($checkDir);
}
}

if($_GET["dir"] == "" || !is_dir($_GET["dir"])) $dir = getcwd();
else $dir = $_GET["dir"];
// replace backslashes, not necessary, but better to look at
$dir = str_replace("\\", "/", $dir);

// show parent path
$pDir = pathinfo($dir);
$parentDir = $pDir["dirname"];

echo "<a href=\"" . $_SERVER["PHP_SELF"] . "\"><h3>Home</h3></a>";
echo "Current directory: " . $dir;
echo "<a href=\"" . $_SERVER["PHP_SELF"] . "?dir=$parentDir\"><h4>Parent directory: $parentDir</h4></a>";

// Display directory content
echo"<table border=1 cellspacing=0 cellpadding=2>
<tr><th align=left>File / Dir</th>";

// specifies the maxDepth of included subdirectories
// set maxDepth to 0 if u want to display the current directory
$maxDepth = 0;
showDir($dir, -1, $maxDepth);

?>
avatar
Mac
Re: TASK 3B-2
August 30, 2007 11:46AM
If I get your Q, a directory can only be browsable (in the manner of a filemanager) if it is defined so on the server, typically in the httpd.conf file. If you can do it with code, then there are security gaps on the server!
Re: TASK 3B-2
August 31, 2007 06:43AM
point noted mac. we don't want no security issues...
Re: TASK 3B-2
September 03, 2007 03:34PM
TASK 3B-2 completed smiling smiley
Re: TASK 3B-2
September 07, 2007 09:34AM
Task completed. Moving along. thumbs up
Re: TASK 3B-2
October 10, 2007 12:11AM
Completed!!
Re: TASK 3B-2
November 07, 2007 07:26PM
grinning smiley cOMPLETED
Sorry, only registered users may post in this forum.

Click here to login