0

I've created a PHP page to upload a file to the server.
I've created a HTML page with javascript that parses a file on the server.

I'd like to upload the file and after a successful upload directly open the HTML page and use the (uploaded) file name as parameter for my javascript.

How to combine these two. I can't get it working.

4
  • Can you post the code that is giving you problem? Commented Dec 12, 2012 at 18:10
  • @ l_h2o_; My problem is to combine these two. Commented Dec 12, 2012 at 18:12
  • From your PHP script you can redirect to the html page something like afterFileUpload.html?fileName={name of the file stored in the php var} is this what you want? Commented Dec 12, 2012 at 18:15
  • @ l_h2o_; Yes or if possible without making the filename visible. Commented Dec 12, 2012 at 18:19

1 Answer 1

1

Umm, there's very little information here, but one way would be to render out your html with a hidden field where the value of the field was the filename. Then you could call getElementById or whatever method you use to find selectors to read that in, then use that in your javascript.

<html>
    <body>
        <span id="submittedFilename" style="display: none"><%php $filename %></span>
    </body>
</html>

<script>
    var filename = $('submittedFilename").html();
</script>

Another option would be to set a variable into your rendered php (html) page, and then use that in your javascript.

<script>
    var filename = <%php $filename %>;
</script>

================ EDIT ==========================

<%php // This is your processing script 
     ... Your processing logic ...

     // After processing, add a variable called filename to session.
     session_start();
     $_SESSION['filename'] = $filename;

     header('Location: /newPhpScript.php');

%>

-- Then your new php script could look something like this:

<%php session_start() %>
<html>
    <body>
        <script>
           // if using jQuery
            var filename = $('#filename').text();
           // else use this
            var filename = document.getElementById('filename').innerHTML;
        </script>
        <span id="filename" style="display: none"><%php echo $_SESSION['filename'] %></span>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

4 Comments

Can you explain this a little more (small example maybe)
This makes the javascript variable a global variable set on load. Therefore, it's accessible to any javascript on the page.
Do i need to open the php first and then pass on the file name to the html page ? OR integrate the php in the html ? (this is new to me)
I modified my answer with a full example (though it may not be exact code, so you may have to tweak it a bit)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.