0

My code is the following

<button onClick="showMoveFile(<?php echo $file_id; ?>, 
\"<?php echo $folder_id; ?>\", 
\"<?php echo addslashes($filename); ?>");\">
   move
</button>

the onClick event is already in double-quotes.

the filename and folder_id are strings.

The problem begins when $filename has an apostrophe in it, like cousin's

For some reason, I cannot escape the 'as I should.

Any suggestions?

thanks!

Adrian Tanase
  • 671
  • 8
  • 20

1 Answers1

-1

Try something like this, use addslashes to escape for js the \\ in the path are required to escape for php Usually pathnames use / to avoid the double escaping

<?php
$file_id = "abc";
$folder_id = 'folder';
$filename = "cousin's";
?>

<button onClick='showMoveFile("<?php echo addslashes("$file_id\\$folder_id\\" . $filename); ?>");'>move</button>

For me that outputs

<button onClick='showMoveFile("abc\\folder\\cousin\'s");'>move</button>
bumperbox
  • 10,166
  • 6
  • 43
  • 66