0

I have a php variable $ext used to take value of a js variable fp

$nam = $_POST['subject'];
$ext = "<script>document.writeln(fp);</script>";

I need to pass the variables into move_uploaded_file function like this

$x = 'uploads/' . $nam . "." . $ext; // a temp variable to join those variables

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $x))

Is it possible ?

httpanand
  • 216
  • 2
  • 17
  • You can't, JS is executed on the client, PHP is executed on the server at very different times. Consider to include `fb` value into a form control element, like `input type="hidden"`. Also, it's dangerous to let a client to name a file on your server, you've at least to validate it carefully to avoid attacks. – Teemu Jan 30 '23 at 07:15
  • In PHP, you can pass a string that contains JavaScript code as an argument to a function by encapsulating the string in single or double quotes. For example: console.log('Hello, World!')"; function passJSScript($jsScript) { echo $jsScript; } passJSScript($jsScript); ?> – Kishor Ahir Jan 30 '23 at 07:21

0 Answers0