Forum Moderators: coopster

Message Too Old, No Replies

PHP post problem

         

andrewsmd

6:59 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a php form that searches a directory that a user specifies and returns files that match their search i.e. C:\some folder\*.txt returns all the text files in c:\some folder. My problem is after I print the output, I write two more buttons that are copy all and copy selected. Basically they will copy the files to another directory. The copy all button works fine and copies all of the files. However, I print checkboxes with the file name as a name and my copy selected won't work. Say I have a checkbox <input type = 'checkbox' name = 'test.txt'>
If I do a print_r on $_POST then [test.txt] => on. However if I do an
if(isset($_POST['test.txt'])) I get a return of false. Does anyone know why.

andrewsmd

8:07 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I figured it out. Using file names as post data doesn't work because it automatically changes any \\ to \ any " " to _ and removes all periods

penders

11:32 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...and removes all periods

I've found that PHP converts all periods to underscores (despite the period being a valid character in the NAME attribute. However, slashes and spaces are not valid in the NAME attribute.) The same happens when you have a

<input type="image"
control. I think the reason stems from the fact that PHP can't have periods in variable names.

If it's any help, I had a very similar problem recently and solved it by using the NAME of the INPUT to reference the NAME of a hidden field, which contained the multi-strange-character string as its value. Something like....

<input type="checkbox" name="fld_file01">  
<input type="hidden" name="file01" value="test.txt">

andrewsmd

1:33 pm on Jan 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since glob returns an array (or hash table technically) I just use the keys, meaning file1.txt would be [0] and file2.txt would be [1] it's not perfect but I have an error check on the copy so it works for me.