-1

I am trying to retrieve parts of the getcwd() method and inserting them into window.open()

the current getcwd() gives me this C:\wamp\www\qa4u\qa4u_working\Presenter

Using this code :

<?php    

if(isset($_POST['genPDF'])){ 

     foreach($_POST['email'] as $email)
     {
       $eid=$_POST['eid'];
?>
             <script type="text/javascript" language="Javascript">

                 <?
                        $stringlink = getcwd();
                        $pieces = explode('\\', $stringlink);
                 ?>                    
                    window.open("http://"+"<?php echo $_SERVER['HTTP_HOST']?>"+"/"+"<?php $pieces[3]?>"+"/"+"<?php $pieces[4]?>"+"/"+"<?php $pieces[5]?>"+"/genPDF.php?eid=<?php echo $eid ?>&email=<?php echo $email ?>");
            </script>

<?php   
     }  

}   
?>

I am trying to achieve this instead :

window.open("http://qna.nyp.edu.sg/qa4u/qa4u_working/presenter/genPDF.php?eid=<?php echo $eid ?>&email=<?php echo $email ?>");

without forming static links is there a way to get the code to work ?

1 Answers1

0

2 issues regarding your code, that I believe prevents it from working.

  1. You're not printing the pieces values. You should use echo, print or a shorthand <?=$var ?>

  2. Since those are PHP variables, you don't need to use the JS + symbol

So, you should update your code:

window.open("http://<?php echo $_SERVER['HTTP_HOST']; ?>/<?php echo $pieces[3]; ?>/<?php echo $pieces[4]; ?>/<?php echo $pieces[5]; ?>/genPDF.php?eid=<?php echo $eid; ?>&email=<?php echo $email; ?>");
Ofir Baruch
  • 10,323
  • 2
  • 26
  • 39