require_once is unable to find the file - php

Hello i have a stupid question i search in stackflow there was lots of answeserd but i couldnt find solution for my problem i want to call a file in php receiving error actually the code is correct but i am receiving a problem error which is:
Warning: require_once(1) [function.require-once]: failed to open stream:
No such file or directory in C:\xampp\htdocs\Upload images\upload.php on line 2
Fatal error: require_once() [function.require]: Failed opening required '1'(include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Upload
images\upload.php on line 2
I am using dreamweaver. i deleted the path with directory and recreated with different name but not solved still prob exist. also i did google there also i didn't find solution ??????? any one please my head is exploding....??????????????????????????????

A quick test on my system reveals that require_once("file") or error_function(); fails with that exact message; require_once("file"); does not.
This is possibly because require_once is a statement rather than a function, and might have different parsing rules, causing your statement to actually be require_once('db.php' or mysql_error());. The PHP or operator with those arguments will return TRUE without calling mysql_error, causing the statement to be require_once(1) (1 == TRUE) - which would generate those messages. This is just my speculation.
tl;dr
Try removing the or mysql_error() from your code. require_once will generate a fatal error anyway. (Warning: Works On My Machineā„¢.)

Try write complete path in require_once(path)

Related

PHP require 'guzzle.phar' throws Fatal Error but on page refresh works

I want to use Guzzle in my project without using Composer(limitation I can't avoid). I have downloaded their phar file in my project directory PROJECT_ROOT/includes/guzzle.phar
Now in my other files if I use require_once or include or include_once it throws Fatal Error below:
PHP Fatal error:
require(): Failed opening required 'phar://guzzle.phar/autoloader.php (include_path='.:/usr/share/php:PROJECT_ROOT/includes') in PROJECT_ROOT/includes/guzzle.phar on line 3
But when I use
require 'includes/guzzle.phar'
it throws the above error first time the page loads but when I refresh it doesn't throw any error and works ok after that.
Over the past two days, I have looked at various SO questions, tried using include_once, include, require_once and adding PROJECT_ROOT to include path but nothing seems to work.
Any help is appreciated and do let me know if any more info is needed. Thanks
The mentioned PHP Fatal error will throw only if the file path is in correct, you can also find Warnings mentioning the file path is incorrect just before the Fatal error.
PHP Fatal error:
require(): Failed opening required 'phar://guzzle.phar/autoloader.php (include_path='.:/usr/share/php:PROJECT_ROOT/includes') in PROJECT_ROOT/includes/guzzle.phar on line
On each Error/Warning/Notice PHP include information about the error cause to help the developer to track the issue.
Failed opening required 'phar://guzzle.phar/autoloader.php
From the above line/code you can find that the guzzle.phar file path is incorrect, try to use an absolute path insted of relative one.
require_once $_SERVER['DOCUMENT_ROOT'].""."includes/guzzle.phar"

No such file or directory error on require_once in php

I am trying to make a login system for my app, and needed to use php for it. However I'm really new to php so I got errors. First of all, I am using a free web hosting for now, so it might be the issue here. That being said, here is the error part of my php:
<?php
require_once 'include/DB_Functions.php';
?>
And it gives me this error:
Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
Fatal error: require_once(): Failed opening required 'include/DB_Functions.php' (include_path='.:/usr/local/php-5.4.45/share/pear') in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
However, my include folder contains all the required php files. So what might be the issue here?
Try this demo code or plz share your folder structure
require_once(__DIR__.'/../include/DB_Functions.php');

PHP: weird usort bug

Everything works fine on my local machine. But when uploading this piece of code to my live server I'm getting a weird warning ...
usort($modules, array('util_SortItem', 'ByOrder'));
Causes this warning:
Warning: include_once(sc3lycp6hmyab.php) [function.include-once]: failed to open stream: No such file or directory in /opt/www/xxx/web/private/Zend/Loader.php on line 146
Warning: include_once() [function.include]: Failed opening 'sc3lycp6hmyab.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /opt/www/xxx/web/private/Zend/Loader.php on line 146
When I remove the usort from my code the warnings disapear.
Any ideas on how I can get rid of this warning?
This has nothing to do with the usort, but with the ByOrder method of the Util_SortItem class that you are telling usort() to call.
You should take a look into the file where that class is defined to see what it does to trigger the error.
One possibility is that it tries to include a class that doesn't exist, which triggers Zend's Autoloader; the other that Zend is trying to create some sort of cache file.
To me it looks like those spammer names. I'd guess it's not related whatsoever. I think you might have something unescaped in your application and it results in someone trying to exploit it ;)
I haven't been able to sort out the isue but I got rid of it by merging two queries and sorting on my SQL server.

Two Errors trying to include .php file: Warning: require(...) AND Fatal error: require() ... (include_path='.;C:\php\pear')

Here is the first error:
Warning: require(/hb/includes/constants.php) [function.require]: failed to open stream: No such file or directory in C:\wamp2\www\hb\includes\connection.php on line 2
And the second error that immediately follows:
Fatal error: require() [function.require]: Failed opening required '/hb/includes/constants.php' (include_path='.;C:\php\pear') in C:\wamp2\www\hb\includes\connection.php on line 2
Here is the line that it doesn't like:
require("/hb/includes/constants.php");
I did install a new version of WAMP, but I know the directories/files are fine and the code worked previously and on another server. It seems like none of my require()'s are working anymore. I tried looking around and some suggested to others that they edit their php.ini, but I don't know what directory I would point to - if you can't tell I'm pretty noobish regarding all things server related.
Any help is appreciated.
First of all, are your really -- really ! -- sure that the file /hb/includes/constants.php, that your are trying to include, exists ?
Considering that the path you requested begins with a /, it looks like you're using an absolute path... that looks like an UNIX path, but you are on a Windows server...
If it exists, and PHP still cannot include it, check :
that it is readable by your webserver (including the directories) -- I'm thinking about UNIX permissions
that there is no open_basedir restriction that would prevent PHP from accessing those files.
BTW, having a warning and a fatal error is the behavior that's to be expected when using require : the warning is normal (it comes from include) ; and the fatal error is the difference between include and require.

Troubleshooting PHP Login connection

I have encountered a problem that I have not come accross yet when setting up a log in page using php.
The page has a error message that relates to line 1 ( require_once('../Connections/Login.php)
that states
[function.require-once]: failed to open stream: No such file or directory
Fatal Error: require_once() [function.require]: failed opening required ... (include_path='.:/usr/share/pear-php5')
I know it is probably really simple and stupid, but I'm really struggling to self-troubleshoot and would really value some help please?
This is where I have been so confused. I also thought the same, that it just couldn't find the file; however the structure is just as you have said:
htdocs/comparison.php (the log in page)
htdocs/Connections/connComparisonLogin.php
Sorry this is going to confuse you, I simplified the actual script in my original question and here is the actual error message:
Warning: require_once(../Connections/connComparisonLogin.php) [function.require-once]: failed to open stream: No such file or directory in /home/fhlinux135/s/suzukigenuine.com/user/htdocs/comparison.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../Connections/connComparisonLogin.php' (include_path='.:/usr/share/pear-php5') in /home/fhlinux135/s/suzukigenuine.com/user/htdocs/comparison.php on line 1
Have I done it all wrong?
I think your require statement should be:
require_once 'Connections/connComparisonLogin.php';
Where is your "Connections/Login.php" relative to the currrent php file.
php will look for the file relative to the current file, or, in one of the directories specified in the "include_path" php.ini setting.
The error just means php can't find the Login.php file. Assuming the page you are calling is index.php you should have a director structure like
-Dir1
|-index.php
-Connections
|-Login.php
Why are you going up a directory in your require statement? Remove the "../" from the beginning of your require_once path.

Categories