I have the following file structure
-- Plugins
-- inParent.php
---- Uploadify
------ inSame.php
------ Uploadify.php
This function was working smoothly till yesterday. But now, If I try to include the inParent.php in uploadify.php using require_once('../inparent.php), It giving me a silly error..saying...
Warning: require_once(../inParent.php) [function.require-once]: failed to open stream: No such file or directory in /home/user/public_html/plugins/uploadify/uploadify.php on line 3
But the file definitely exists...
The same code when used to include inSame.php shows no error and works perfectly..
I guessed that there could be file permission problem.. But everything is fine..all the related files have 755/644 permissions.
Also, the move_uploaded_file function has also stopped working.
All the code was working fine till yesterday. I hav'nt changed anything.
I have tried everything and dont know what exactly happened..
Please help me friends.. :( :(
I've googled and found this :
require_once __DIR__.'/../inParent.php';
In my case I had to write:
require_once dirname( __FILE__ ) . '/' . '../../inParent.php';
And that worked!
This question is old, but for people like me who run across it, here is an answer from another part of Stack Overflow.
require_once($_SERVER['DOCUMENT_ROOT'] . '/inParent.php');
PHP require file from top directory
If it was working yesterday and you are certain you did not change anything, then try a server restart first.
Second, on require once try using the full path instead of .. I normally create a file with my root paths and referance those instead of using ./ and ../
In my case it is really weird:
This Works perfect:
require('../../the_folder/the_file.php');
But PHP gives an error if i write that as this:
require('../the_file.php');
Please see that in case 2 i do not go up two steps (../../) and then down to the folder, i directly go up one step (../).
Why is PHP giving the error Failed to open stream: No such file or directory in ... ? It is really weird.
This also works:
require(__DIR__.'/../the_file.php');
Thanks for the TIP.
Related
I have the following code
require_once "../pages/appconfig.php";
require_once "../freezer/data_functions.php";
Starting yesterday I'm getting the following error on the second file
failed to open stream: No such file or directory in
for both of these files. It has been working up until today.
echo realpath("../freezer/data_functions.php");
I get the correct full file path of the file that exists on disk.
I made a bunch of changes to other files but none that should affect these calls.
What could be causing this?
It turned out that as part of the appconfig.php includes I was calling a function that called
chdir(__DIR__ . "\\..\\");
and even though I changed it back again, I still got these odd issues. Removed the call to chdir and problem solved.
I have a script that includes a file and that file has an include in it, like this:
In script:
include('includes/functions/homepage.php);
In homepage.php:
include('includes/functions/parent_functions.php');
I searched here and see it is a very common problem and the solution seems to be to use
include(dirname(__FILE__) . '/includes/functions/homepage.php');
I have the above and still get this error:
Warning: include(includes/functions/parent_functions.php): failed to open stream: No such file or directory
I've tried this on a site running php 5.5 and another using 7.2 - fails the same on both. If I print the path using the following it shows the correct full path.
echo dirname(__FILE__) . '/includes/functions/homepage.php';
As mentioned, this is a common question here but the fix isn't working in my case. Can anyone see why?
Well, you have an issue here. As the parent_functions.php and homepage.php are in the same directory you need not put an extra directory prefix. You can simply use
include('parent_functions.php');
instead of
include('includes/functions/parent_functions.php');
I wrote this code in a test.php file.
<?php
include ($_SERVER["DOCUMENT_ROOT"].'/MySite/protected/MyYouTube/google/src/Google/autoload.php');
require_once ($_SERVER["DOCUMENT_ROOT"].'/MySite/protected/MyYouTube/google/src/Google/Client.php');
require_once ($_SERVER["DOCUMENT_ROOT"].'/MySite/protected/MyYouTube/google/src/Google/Service/YouTube.php');
?>
If I go to this file like this: localhost/MySite/protected/MyYouTube/test.php it works, but if I copy the same code into my controller that is located under the same folder as test.php, I get this:
include(Google_Service.php): failed to open stream: No such file or
directory
There are no conflicts with the imports. In fact, the controller and view can be empty and still I get the same thing.
Apparently that happens when autoload.php is not actually loaded.
How is it possible that when the code is integrated into the website it throws this error?
This is what the path to my site looks like:
localhost/MySite/index.php/user/view It seems that the way I visit the file matters.
I tried several things. I tried importing the test.php into my view or my controller, and still I get the same error. I tried using Yii::app()->basePath and it gives the same problem.
The paths are correct, I have checked several times. How can I fix this?
The include path is actual server path, not site path, if you use / at the beginning, you are telling it to look in the server root.
If you know the absolute path in the server you can use it like /var/www/MySite or c:\mysiteif you don't know that then you use relative paths.
$_SERVER["DOCUMENT_ROOT"] works well with PHP 5.3, not sure if below check your version. Try removing the '/' before the MySite part, as the variable already does it for you so it might be printing like localhost//MySite, although I'm not sure if that should or shouldn't work. ]
Also the autoload php should be loaded with a require_once function, not with the include. Good luck!
I tried to reorganise my facebook application files into better folders and now when I try to load my application on facebook it throws the following error:
Warning: require_once(../scripts/mysql_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
Fatal error: require_once() [function.require]: Failed opening required '../scripts/mysql_connect.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
The second error is a result of the failure of the first one I think. The weird thing is that my program works perfectly fine when I'm accessing through the localhost url in the browser but when I run it through facebook it throws this error.
In my root folder I have a "Model" folder where the Database.php file is kept and a "scripts" folder where the mysql_connect.php file is kept. I have tried clearing my cache on the browser and using private browsing but it is still throwing this error.
Does anyone know what could be wrong?
EDIT: Sorry this does not seem to be working in localhost either now! One thing I think is weird is that it says "failed to open stream : NO SUCH FILE OR DIRECTORY IN" and then lists the database.php path. Why is it looking in there?
I use the line require_once('../scripts/mysql_connect.php'); at the top of my Database.php file to include it.
It seems that on the server there is a different working directory. Something like the following owuld be a quick fix
dirname(__FILE__) . '/../scripts/mysql_connect.php'
Ok I've fixed this, but I'm still unsure why it was a problem. In my root folder I have two folders: scripts, and Model. I have a database.php file in my Model folder which has the following line of code in:
require_once('../scripts/mysql_connect.php');
For some reason this did not work, but by replacing the line with:
require_once('/scripts/mysql_connect.php');
This started working again! Just thought I would post the solution. Does anyone know why the other way failed? I thought the ".." just makes it go up one level in the folder hierarchy i.e. to the root folder in this case, and then follow the path which would have taken it to the file...
EDIT: This appears to only have solved it for localhost and not through Facebook...
Do you have permission to edit your php.ini file? One solution would be to find the line with the include path (you'll notice it has C:\xampp\php\PEAR in there already). Include the full path to the "scripts" folder you're referencing, then you can change the php code to read:
require_once('mysql_connect.php');
PHP will be able to find this file since it's in the include path. Just make sure that if you start adding several include paths that you shouldn't have a file named mysql_connect.php in two or more of the different include paths because you'll most likely get errors. Hope this helps. It definitely makes for some cleaner code.
I have a directory layout something like /public_html/foo/bar.php that I want required in my file with my file require statement being currently require('../foo/bar.php') but I'm not getting to it (I keep getting an error saying its not a directory? and failed to open stream).
My file that I'm putting the require in is in /public_html/foo2/ so I need to go up one directory listing and then find the file to include it but I'm not sure what I'm doing wrong right now. Any guesses?
Actual code:
require('../objects/user.php/');
Thanks for your help!
You have a / behind your ../objects/user.php suggesting user.php is a directory.
That's why it tells you it is not a directory, because it indeed isn't.
Remove it and you'll probably be fine. (so ../objects/user.php/ becomes ../objects/user.php)