0
0
0x70002021-11-02 08:17:31
AJAX
0x7000, 2021-11-02 08:17:31

How to pass upload file name from js variable to php?

How can I asynchronously pass the name of the uploaded file from a js variable to a php variable and echo it out?

Download form:

<div id="upload">
<form action="upload.php" method="post" target="hiddenframe" enctype="multipart/form-data" onsubmit="hideBtn();">
<br>
<input type="file" id="userfile" name="userfile" />
<input type="submit" name="upload" id="upload" value="Загрузить" />
</form>


PHP:
if($_POST['userfile']) {
    $str = $_POST['userfile'];
   }
   echo $str;


JS:

var filename = document.getElementById("userfile").files[0].name;
  alert(filename);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-11-02
@0x7000

XMLHttpRequest , fetch , axios

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question