Warning: include(Math.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\php ModulesAndNamespaces\php modules & namespaces.php on line 13
<?php
// modules-> divide and reuse codes
//Math.php
define( 'PI', 3.14);
function add($a,$b) {
echo $a+$b;
}
?>
<?php
//App.php
include ('Math.php');
echo PI;// 3.14
echo add(1,2);//3
?>
Why do I get this error, and how can the problem be fixed?
Related
I have these errors when running my script.
failed to open dir: No such file or directory in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Warning: scandir(): (errno 2): No such file or directory in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Warning: array_diff(): Argument #1 is not an array in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/sites-store/word/word2.php on line 7
Well this is my code below, I don't understand why it failed to open my dir when it's being declared below? Can someone help me with this.
Code of my word2.php
<?php
$numargs = count($argv);
if ($numargs > 1) {
$folder = $argv[1];
echo "Folder is: " . $folder . "\n";
$files = array_diff(scandir($folder), array('.', '..')); //line 6
foreach ($files as $file) { //line 7
$filename = str_replace("í»", "", $filename);
}
} else {
echo "You need to pass the folder absolute path";
exit();
}
Code for running my script using this command ./run.bat this is the filename with a code below.
php word2.php "/Applications/MAMP/htdocs/sites-store/word/images"
PAUSE
Try changing your .bat file to
php word2.php -- "/Applications/MAMP/htdocs/sites-store/word/images"
PAUSE
and you should also do var_dump($argv), to see how your script gets its parameter.
failed to open dir: No such file or directory in
/Applications/MAMP/htdocs/sites-store/word/word2.php on line 6
Make sure that your file in that directory.
Check the filename again means is there any spelling mistakes or duplicated.
Make sure if it's read that directory or not
I am using phpMYADMIN and netbeans for coding, when pressing run project in netbeans at the top of my page I get this error: `
Warning: include(utils/mysql.class.php): failed to open stream: No such file or directory in C:\xampp1\htdocs\autonuoma\index.php on line 6
Warning: include(): Failed opening 'utils/mysql.class.php' for inclusion (include_path='C:\xampp1\php\PEAR') in C:\xampp1\htdocs\autonuoma\index.php on line 6
My whole is index.php is:
<?php
// nuskaitome konfigūracijų failą
include 'config.php';
// iškviečiame prisijungimo prie duomenų bazės klasę
include 'utils/mysql.class.php';
// nustatome pasirinktą modulį
$module = '';
if(isset($_GET['module'])) {
$module = mysql::escape($_GET['module']);
}
// jeigu pasirinktas elementas (sutartis, automobilis ir kt.), nustatome elemento id
$id = '';
if(isset($_GET['id'])) {
$id = mysql::escape($_GET['id']);
}
// nustatome, kokia funkcija kviečiama
$action = '';
if(isset($_GET['action'])) {
$action = mysql::escape($_GET['action']);
}
// nustatome elementų sąrašo puslapio numerį
$pageId = 1;
if(!empty($_GET['page'])) {
$pageId = mysql::escape($_GET['page']);
}
// nustatome, kurį valdiklį įtraukti šablone main.tpl.php
$actionFile = "";
if(!empty($module) && !empty($action)) {
$actionFile = "controls/{$module}_{$action}.php";
}
// įtraukiame pagrindinį šabloną
include 'templates/main.tpl.php';
?>
When I click some menu option in the webpage it returns an error also:
Warning: include(utils/mysql.class.php): failed to open stream: No such file or directory in C:\xampp1\htdocs\autonuoma\index.php on line 6
Warning: include(): Failed opening 'utils/mysql.class.php' for inclusion (include_path='C:\xampp1\php\PEAR') in C:\xampp1\htdocs\autonuoma\index.php on line 6
Fatal error: Uncaught Error: Class 'mysql' not found in C:\xampp1\htdocs\autonuoma\index.php:11 Stack trace: #0 {main} thrown in C:\xampp1\htdocs\autonuoma\index.php on line 11
My question is, what is causing this? The webpage is loading, but it doesn't let me click anything since mentioned error occurs. I know this might sound very silly but I cannot locate the error
`
Hello all this is a simple question which is already there in stack overflow but I tried all the possible answers still it's not fixed
I need to include config file which is under assets folder i tried the following code
include_once '../config.php' ;
am getting error like this
Warning: include(assets/config.php): failed to open stream: No such file or directory in E:\xampp\htdocs\project\assets\handler\ContactHandler.php on line 4
Warning: include(): Failed opening 'assets/config.php' for inclusion (include_path='E:\xampp\php\PEAR') in E:\xampp\htdocs\project\assets\handler\ContactHandler.php on line 4
kindly suggest me a possible way to include config file in ContactHandler.php
ContachHandler.php
<?php
include_once 'E:\xampp\htdocs\project\assets\config.php';
echo "ddddd";
exit;
include (CONTROLLER.'ContactController.php');
$form = $_POST['form'];
$cnt_controller = new ContactController();
switch ($form)
{
case 'AddContact':
$cnt_controller->AddContact($_POST);
break;
case 'ContactUs':
$cnt_controller->ContactUs($_POST);
break;
}
?>
Check to see if your include path changed and check file/folder permissions.
Try out this code:
<?php
$config_path = '../config.php' ;
if (file_exists($config_path)){
require_once $config_path;
}
else {
$config_path = 'config.php';
if (file_exists($config_path)) {
require_once $config_path;
}
else {
$config_path = '../../config.php';
require_once $config_path;
}
}
echo "ddddd";
echo $config_path;
exit;
?>
For testing set static path:
include_once 'E:\xampp\htdocs\project\assets\config.php';
Hope this helps!
This question already has answers here:
PHP - Failed to open stream : No such file or directory
(10 answers)
Closed 5 years ago.
I am just trying to make a simple PHP program that allows me to generate my page quickly.
I am completely new at PHP.. And I have no clue what I am doing.
/index.php
<?php
include "/base/startup.php";
echo "Test";
startPage("Home");
?>
I'm getting a 500 server error with this.. Please tell me what I'm doing wrong. Thank you.
/base/startup.php
$HOME = "/";
$SCRIPT = <<<EOD
EOD;
$IMPORTS = array(
"/scripts/script.js"
);
$STYLES = array(
"/styles/style.css"
);
function prnt($string) {
echo $string;
}
function map($func, $arr) {
foreach($arr as $i) {
call_user_func($func, $i);
}
}
function linkScript($script) {
prnt("<script src='$script'></script>");
}
function linkStyle($style) {
prnt("<link rel='stylesheet' href='$style'/>");
}
function startPage($title, $script="", $imports=array(), $styles=array()) {
$pre_tags = array(
"<html>",
"<head>"
);
$post_tags = array(
"</head>",
"<body>"
);
map(prnt, $pre_tags);
prnt("<title>$title</title>");
map(linkScript, $IMPORTS);
map(linkScript, $imports);
map(linkStyle, $STYLES);
map(linkStyle, $styles);
map(prnt, $post_tags);
}
function genNav() {
$nav_links = array(
"Home"=>$HOME,
"Walkthroughs"=>$HOME . "/walkthroughs/",
"Dex"=>$HOME . "dex.php"
);
prnt("<div class='nav'>");
foreach ($nav_links as $key => $value) {
prnt("<a class='link' href='" . $value . "'/>" . $key . "</a>");
}
}
function endPage() {
$endTags = array(
"</body>",
"</html>"
);
}
?>
This is the error:
Warning: include(/base/startup.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 2
Warning: include(): Failed opening '/base/startup.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/index.php on line 2
Test
Fatal error: Uncaught Error: Call to undefined function startPage() in /var/www/html/index.php:4 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 4
Since you mentioned you are on a Linux machine, it looks like the issue is caused because of the / here. The / is considered the root directory of linux machine. So removing the / must most probably work:
<?php
include "base/startup.php"; // Try removing the slash.
echo "Test";
startPage("Home");
?>
Since you haven't enabled the display of errors, the issue would be, there's no /base in your system and it would have thrown an error, like Fatal: Include file not found., which is not displayed because of your configuration, instead it would have shown Error 500 silently.
Update
Along with the above error, after seeing your code, the next one is you need to quote the function names. So replace the stuff with:
map("prnt", $pre_tags);
prnt("<title>$title</title>");
map("linkScript", $IMPORTS);
map("linkScript", $imports);
map("linkStyle", $STYLES);
map("linkStyle", $styles);
map("prnt", $post_tags);
The next error is, you haven't included the global variables correctly inside the function. You need to use:
global $IMPORTS, $STYLES;
Now your code works as expected.
And finally finishing the endPage() function:
function endPage() {
$endTags = array(
"</body>",
"</html>"
);
foreach($endTags as $tag)
echo $tag;
}
The php code grabs values from a form and writes it to flat file. This code works locally but when I place it on the host I get the the two errors. Local instance doesn't require a config.php in the directory but the host file does.
error1: states that there is no config.php
error2:I have to specify a path but if
? - what do I put in the config file so it allows me to create the flat file or can I reference the file same how??
any help would be appreciated.
CODE:
<html>
<head>
<title>test</title>
</head>
<body>
<?php
include('config.php');
$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen( $_SERVER['DOCUMENT_ROOT'] . '/flatfile/test/' . $user . '.txt', "a" );
if (!$out) {
print("Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"<b>$user</b><br />$message<br /><br />");
fclose($out);
?>
</body>
</html>
ERROR:
1
Warning: include(config.php) [function.include]: failed to open stream: No such file or directory in /home/user1/flatfile/sendinfo.php on line 7
2
Warning: include() [function.include]: Failed opening 'config.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/user1/flatfile/sendinfo.php on line 7
You have 2 ways: create config.php or remove include.
Are you sure the config.php file is in the right directory you can check if the file exist and then include like this
if (file_exists('config.php')) {
include('config.php');
}
http://php.net/manual/en/function.file-exists.php