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>";         

}

Link to comment
Share on other sites

  • 2 weeks later...
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.