A
Anonymous
Guest
Hello to you all,
I have a problem understanding how to use __DIR__ constant
Here is the code of the file main.php . It works well
Here is the code for form.html.php
Here is the code for welcome.html.php
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 do I take advantage of the __DIR__ constant if It fails when I move the including file to a new directory?
I have a problem understanding how to use __DIR__ constant
Here is the code of the file main.php . It works well
Code:
<?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';
}
?>
Code:
<!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
Code:
<!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 do I take advantage of the __DIR__ constant if It fails when I move the including file to a new directory?