Jump to content

[SOLVED] Directory Listing..


Jaquio

Recommended Posts

Alright, well I have EVERYTHING listed... It is just when you try to click on anything including an '(quotesingle Apostrophe) it cuts it off right there... So something like, "Samantha's Strip Tease.mpg" cuts off into "Samantha" and nothing else.. No it isn't nothing containing nudity just some of us screwing around at school being bored. But yea, anyway to fix this? Here is what I am using. REALLY Sloppy I know, but am just trying new things.

 

<?php
$HomeDir = "/Videos/";
echo ("
<BODY BGCOLOR=BLACK TEXT=WHITE LINK=GREEN VLINK=ORANGE ALINK=ORANGE>
");
if ($TheDir == null or $TheDir == "Home/")
{
    $Files = LoadFiles('./');
    SortByType($Files);
    SortByType($Dirs);
    echo("
	<H1><b><u>Music</u></b></H1>
	<H2>
");
    while (list($k, $v) = each($Dirs))
    {
        echo ("<a href='?TheDir=$v[0]'>$v[0]</a><BR>");
    }
    while (list($k, $v) = each($Files))
    {
        echo ("$v[0]<BR>");
    }
}
else
{
    $Files = LoadFiles($TheDir);
    SortByType($Files);
    SortByType($Dirs);
    echo ("
    	<H1><b><u>$TheDir</u></b></H1>
	<H2>
");
    
$TheCDir = "../Videos/".$TheDir;
    $CDir = explode("/", $TheCDir);
    if(count($CDir) == 4){
	$HDir = count($CDir) - 2;
	$DirN = "Home"."/";
} else {
	$HDir = count($CDir) - 3;
	$DirN = $CDir[$HDir]."/";
}
echo("
	<a href='?TheDir=$DirN'>$DirN</a><BR>
");
    while (list($k, $v) = each($Dirs))
    {
        echo ("<a href='?TheDir=$TheDir$v[0]'>$v[0]</a><BR>");
    }
    while (list($k, $v) = each($Files))
    {
        echo ("<a href='$TheDir/$v[0]'>$v[0]</a><BR>");
    }
}

function LoadFiles($dir)
{
    global $Dirs;
    $Exts = array("ni", "ll", "pg", "hp", "db");
    $Files = array();
    $Dirs = array();
    $It = opendir($dir);
    if (!$It)
        die('Cannot list files for ' . $dir);
    while ($Filename = readdir($It))
    {
        if ($Filename == '.' || $Filename == '..')
            continue;
        $FileType = @filetype($dir . $Filename);
        if ($FileType == "dir")
        {
            $Dirs[] = array($Filename . "/", $FileType);
        }
        else
        {
            if (!in_array(substr($Filename, strlen($Filename) - 2), $Exts))
            {
                $Files[] = array($Filename, $FileType);
            }
        }
    }

    return $Files;
}

function SortByType(&$Files)
{
    sort($Files);
}
?>

Link to comment
Share on other sites

I fixed it, might be sloppy as well but it works. But I had to replace the + with %20s so:

 

<a href=".str_replace("%2F", "/", str_replace("+", "%20", urlencode($TheDir.$v["0"]))).">$v[0]</a><BR>

 

worked, thanks for your help with urlencode.

Link to comment
Share on other sites

Ran into another problem... Folders including an ' give me an error...

 

"Warning: opendir(../Friends/Samatha's Stuff/) [function.opendir]: failed to open dir: No error in C:\WS\htdocs\Friends\index.php on line 131

Cannot list files for ../Friends/Samatha's Stuff/"

 

Now I know I could rename the folder and remove ' but I've got a lot of other folders with it and don't feel like renaming them all...

Link to comment
Share on other sites

Now I know I could rename the folder and remove ' but I've got a lot of other folders with it and don't feel like renaming them all...

 

Sounds like a Windoze-induced deathwish. The _underscore_ is your friend: sensible file names and sensible folder names will save you headaches :)

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.