Jump to content

file and directory listing not working if files have spaces


diddy1234

Recommended Posts

I was wondering if someone could help me.

 

I have a script that gives a listing of a directory and files, however if the file has spaces the file is listed correctly but it does not appear to handle a selected file.

 

so for example if a file is shown as 'test 123.txt' the selected file will be 'test' with the 123.txt chopped off.

The same applies to directory names with spaces as well.

 

How do i handle this ?

 

The script is a mixture of what i found on the web and my own customisation to get a directory to be selectable.

 

Thanks in advance.

 

script :---

function ListFiles($path, $tdir)

{

 

        // List files

        //

 

        $filearray=array();

$dirarray=array();

$dirs = scandir($tdir);

 

        $i=0;

$l=0;

foreach ($dirs as $file)

        {

if($file != '.' && $file != '..')

{

if (is_dir($tdir . '/' . $file))

{

// Is dir

$dirarray[$l]=$file;

$l++;

 

}

else

{

// Must be a file then,

$filearray[$i]=$file;

$i++;

 

}

}

}

 

// Put into order

        sort($filearray);

sort($dirarray);

 

        echo "<table border=\"0\" cellspacing=\"0\">";

 

for($l=0; $l<sizeof($dirarray); $l++)

{

$dir=$dirarray[$l];

echo "Directory of: <a href=\"?mode=list&dir=" . $tdir . $dir . "\">" . $dir . "</a><br>";

}

echo "<br>";

        for($i=0; $i<sizeof($filearray); $i++)

        {

$film = substr($filearray[$i], 0 , -4);

                echo "<tr>";

echo "<td><a href=\"?mode=player&dir=" . $tdir . "&film=" . $film . "\">" . $film . "</a></td>";

 

        }

 

        echo "</table>";         

}

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.