0

I'd like to use my variable inputFiles from my Javascript in my PHP file. Here you have the following code:

<html>

    <body>
        <form action="action.php" method="post">
            <input type="file" name="files" id="files" multiple>
            <button type="submit" name="send_files" onclick="printFiles()">Send files</button>
        </form>
        
        <script>
            function printFiles(){
                let inputFiles = document.getElementById("files");
                
                let inputArray = Array.from(inputFiles.files);
                //console.log(inputFiles);
                //inputArray = inputArray.forEach(element => console.log(element));
            }
            
            
        </script>
    </body>

</html>

I have already tried it but it doesn't work: echo "<script>document.writeln(inputFiles);</script>;

Thank you for your help!

Seeyoz
  • 1
  • PHP is a server-side language. It finished executing long ago, in a different computer, before the generated HTML and JavaScript reached the browser. – Álvaro González Jun 24 '22 at 16:36
  • Use [XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) to send your client-side information back up to the server for PHP processing. I wrote a detailed answer on a similar subject here: https://stackoverflow.com/questions/72022099/how-to-make-the-value-stored-in-the-php-session-update-with-the-ajax-submission/72023066#72023066 – bloodyKnuckles Jun 24 '22 at 19:30

0 Answers0