PHP require_once error when including file in parent folder

China☆狼群 提交于 2021-02-07 11:32:11

问题


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.. :( :(


回答1:


I've googled and found this : require_once __DIR__.'/../inParent.php';




回答2:


In my case I had to write:

require_once dirname( __FILE__ ) . '/' . '../../inParent.php';

And that worked!




回答3:


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




回答4:


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 ../



来源:https://stackoverflow.com/questions/12242964/php-require-once-error-when-including-file-in-parent-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!