Hello to you all,
I have a problem understanding how to use DIR constant
Here is the code of the file main.php .All works well
_<?php_
_if(!isset($_POST['firstname'])){_
_ include __DIR__ .'/../../form.html.php';_
_}else {_
_ $firstname = $_POST['firstname'];_
_ $lastname = $_POST['lastname'];_
_ if ($firstname =='Kevin' && $lastname == 'Yank'){_
_ $output = 'Welcom, Oh glorious leader!';_
_} else {_
_ $output = 'Welcome to our website, ' .htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') .' ' . htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';_
_ _
_}_
_include __DIR__ .'/../welcome.html.php';_
_}_
_?>_
Here is the code for form.html.php
_<!DOCTYPE html>_
_<html>_
_ <head>_
_ <title> Enter your name </title>_
_ <link rel="stylesheet" href="form.css" />_
_ <meta charset="utf-8">_
_ _
_ </head>_
_ <body>_
_ <form method="POST" action="">_
_ <label for="firstname">First name:</label>_
_ <input type="text" name="firstname"id="firstname" />_
_ <label for="lastname">Last name:</label>_
_ <input type="text" name="lastname"id="lastname" />_
_ <input type="submit" value="GO">_
_</form>_
_ </body>_
_</html>_
Here is the code for welcome.html.php
_<!DOCTYPE html>_
_<html>_
_ <head>_
_ <title> Form Example </title>_
_ <meta charset=""utf-8">_
_</head>_
_ <body>_
_ <p><?php echo $output;?></p>_
_ </body>_
_</html>_
If I understand correctly, the DIR “knows” where the including file is located so that if I move the file to a new directory it should work without updatind the code.
Yet, when I created a newdirectory and I cut and pasted the file there. I didn’t work
I got these messages:
Warning: include(C:\wamp\www\PracticePhP\templates\PHPPRA\STILL/…/…/form.html.php): failed to open stream: No such file or directory in C:\wamp\www\PracticePhP\templates\PHPPRA\STILL\main.php on line 3
And
Warning: include(): Failed opening ‘C:\wamp\www\PracticePhP\templates\PHPPRA\STILL/…/…/form.html.php’ for inclusion (include_path=‘.;C:\php\pear’) in C:\wamp\www\PracticePhP\templates\PHPPRA\STILL\main.php on line 3
Line 3 is where the 1st include is.
I work on wamp at home.
It isn’t a problem of pesmissions
How can I take advantage of thr DIR constant if I move the including fileand the code fails