Problem Passing File Names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jacob Lyles

    Problem Passing File Names

    Hello,


    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 />";
    }
    }
    closedir($dh);
    }
    }
    }

    Any help would be appreciated.

    Thanks,
    Jacob

  • Jacob Lyles

    #2
    Re: Problem Passing File Names

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


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

    Comment

    • Toby Inkster

      #3
      Re: Problem Passing File Names

      Jacob Lyles wrote:
      [color=blue]
      > ./directory/file.extention as expected. However, the value in
      > the name field of the input tag gets passed through POST as
      > /_/directory//file_extention[/color]

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

      <http://uk2.php.net/variables.exter nal>
      (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 ~ http://tobyinkster.co.uk/contact

      Comment

      Working...