-1

I have "upload.php" page which consists of upload form and radio button form.

<html lang="en">
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="my_upload">1) Select a file to upload:</label>
<input id="my_upload" name="my_upload" type="file">
<input type="submit" value="Upload">
</form>

<form action="./execute.php">
<input type="hidden" name="parameter"  value=" ? ">
<input type="radio" name="mode" value="one">one<br>
<input type="radio" name="mode" value="two">two<br> 
<input type="submit" value="Execute">
</html>

<?php
... php upload code ...
$parameter;

When I select file to upload and press button "Upload", php code on the same page "upload.php" starts running. After it finishes, I would like to take value "$parameter" and use it in html code on the same page, in next form with radio buttons. Is there a way to do this? Also, is there a way to get values/variables from "execute.php" after it is actually executed and use them on page "upload.php"?

jurij
  • 383
  • 3
  • 7
  • 21
  • 3
    Have you read this documentation on file uploading on the PHP website? https://www.php.net/manual/en/features.file-upload.post-method.php – Josef Engelfrost Nov 09 '19 at 21:20
  • It is just an example, I am interested in variables/parameters, not in the actual upload itself. :) Thanks! – jurij Nov 09 '19 at 21:22
  • No, sorry, it does not. The actual function of upload is not important in my question. – jurij Nov 09 '19 at 21:26
  • [Didn't you ask something like this earlier?](https://stackoverflow.com/q/58782613/1415724) – Funk Forty Niner Nov 09 '19 at 21:31
  • @FunkFortyNiner No, I asked there about passing parameters in URL between different PHP pages. I am now interested in using/passing parameters between PHP and HTML on the same page. Thanks! – jurij Nov 09 '19 at 21:33
  • Possible duplicate of [Upload a file using PHP](https://stackoverflow.com/questions/35253550/upload-a-file-using-php) – hkoosha Nov 10 '19 at 06:41
  • Not a duplicate ... – jurij Nov 10 '19 at 07:56

1 Answers1

1

Just place your php code above your html stuff:

<?php
... php upload code ...
$parameter;
?>

<html lang="en">
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="my_upload">1) Select a file to upload:</label>
<input id="my_upload" name="my_upload" type="file">
<input type="submit" value="Upload">
</form>

<form action="./execute.php">
<input type="hidden" name="parameter"  value="<?php echo $parameter ?>">
<input type="radio" name="mode" value="one">one<br>
<input type="radio" name="mode" value="two">two<br> 
<input type="submit" value="Execute">
</form>
</html>

And close the second form with /form.

Marco
  • 3,470
  • 4
  • 23
  • 35