Problem Passing File Names

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm using the following function to display a list of files in a
directory in a HTML form that allows the user to delete files. Look at
the echo line. The links work fine, taking a user to
./directory/file.extention as expected. However, the value in the name
field of the input tag  gets passed through POST as
/_/directory//file_extention, which messes up my unlink function. The
strange thing is I'm using \"/$dir/$file\" for both of them, so POST
must be doing something to my string.

function checklist_dir($dir) {
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if (filetype($dir . $file) != dir) {
                    echo "<input type=\"checkbox\" name=\"/$dir/$file\" /><a
href=\"/$dir/$file\">$file</a><br />";

Any help would be appreciated.  


Re: Problem Passing File Names

Ugh, sorry, that code looks ugly. Here's the lines in question once

echo "<input type=\"checkbox\" name=\"/$dir/$file\" /><a
href=\"/$dir/$file\">$file</a><br />";

Again, the link made with \"/$dir/$file\" works fine, taking a user to
./directory/file.extention while the name field is getting passed as
/_/directory//file_extention when I look at it using

foreach ($_POST as $key => $value) {
     echo "$key<br />";

Re: Problem Passing File Names

Jacob Lyles wrote:

Quoted text here. Click to load it

Dots in form values are replaced with underscores in PHP. This is a
throwback to when you would use $foo instead of $_POST['foo'].

(Heading: Dots in incoming variable names)

There's not really any way around it, so it might be worth using, e.g.
base64encode() and base64decode() at each end, as base64-encoded data
never contains dots.

Toby A Inkster BSc (Hons) ARCS
Contact Me  ~

Site Timeline