This is a discussion on Is $file\n a string variable? Why does it echo ok but mess up my fuction? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have a block of code that opens a directory and creats a file list with a small button image ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a block of code that opens a directory and creats a file list with a
small button image next to each name. Above this list is a blank form, with some text boxes. My plan is to add some Javascript so that I can drag the button to my form and have a text box populate with the file name from the button I just dragged each file so that I can drag the image next to each file name in to a form text box and have I can echo "$file\n" to get the file name to appear in its spot in the list. however when I try and use $file\n inside the function event.dataTransfer.setData("TEXT",'$file\n') I get an undertermined string constant error. It only takes a slight change to the code to get it to work which makes me think the probem is with the $file\n If I change the event.dataTransfer.setData to event.dataTransfer.setData("TEXT",'dog') everything works fine and I get dog in the box if I drag the image. I thought maybe I could not use a variable inside this fuction however if I put event.dataTransfer.setData("TEXT",'$Z') I get the value of the $Z loop counter Do I need to convert $file\n to a string first? If so how can I do this. My code is below. Otherwise what is differnt about $file\n then my $Z counter that I cant pass it to the even.dataTranfer.setData function? Rich <?php // This block is the file browse code if ($handle = opendir('../docs/')) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { $Z=$Z+1; echo "$file\n <IMAGE ID='a$Z' SRC='button.gif' ondragstart='a$Z()'> $Z<BR> <SCRIPT> function a$Z() /* The setData parameters tell the source object to transfer data as a URL and provide the path. */ { event.dataTransfer.setData('TEXT', '$file\n' ); } </SCRIPT> "; } /* This is the WRONG way to loop over the directory. */ while ($file = readdir($handle)) { echo "$file\n"; } closedir($handle); } ?> |
|
|||
|
On Sun, 1 Feb 2004 22:28:50 -0500, "Rich Zellmer"
<tdmailbox@yahoo.com> wrote: >I can echo "$file\n" to get the file name to appear in its spot in the list. >however when I try and use $file\n inside the function >event.dataTransfer.setData("TEXT",'$file\n') I get an undertermined string >constant error. Try: "$file\n" Single and double quotes are evaluated differently. Or: $file."\n" |