3

I have a situation where a php line is working fine on localhost but not on live server, even if I have the same file and folder structure.

require_once '/../Renderer.php';

The error I am getting on live server is:

Warning: require_once(/../Renderer.php): failed to open stream: No such file or directory in /home2/attafsir/public_html/balaghatoalquran/production/wp-content/themes/twentyten/Text/Diff/Renderer/unified.php on line 19

Fatal error: require_once(): Failed opening required '/../Renderer.php' (include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in /home2/attafsir/public_html/balaghatoalquran/production/wp-content/themes/twentyten/Text/Diff/Renderer/unified.php on line 19

I have spend a lot of time trying to figure out what could be the reasons behind such behaviour, but to no avail, your help is appreciated.

PS: I have verified with my host if PEAR is installed and configured in php.ini, and they confirm it to me. (since the code is using PEAR package)

Solution: The solution is the accepted answer, but I want to notice though that the problem on live server is resolved but broke the functionning on localhost. This is a temporary solution since the best thing is to have the same code on local and live server. I will be back to post a full solution when I find it. your suggestion are always welcome.

Adib Aroui
  • 4,981
  • 5
  • 42
  • 94

6 Answers6

4

/ is the root of the file-system and then you try to go up one level with ... That does not exist so you get an error.

Are you sure you do not want a relative path?

If you want it to be relative to the root of the web-server (which is not the root of the file-system unless there is something very wrong), use something like:

$_SERVER['DOCUMENT_ROOT'] . '/../Renderer.php'
jeroen
  • 91,079
  • 21
  • 114
  • 132
  • 1
    I inspired from your answer to find the solution (which unfortunately break the functionnnig on localhost). – Adib Aroui Apr 11 '14 at 15:14
  • 2
    @whitelettersandblankspaces It shouldn't, if your local web-server is correctly set up, `$_SERVER['DOCUMENT_ROOT']` should give you the root folder of your web-site. – jeroen Apr 11 '14 at 15:18
  • what are you saying is logical, but I still dont understand why I should put different lines of code in the same file while passing from localhost to live.this behavior never appeared in the whole website except for `require_once`.thank you for your time – Adib Aroui Apr 11 '14 at 15:24
  • 2
    If you were using html links, / is your document root. in php, it is the filesystem root. Try changing to include_once, include, or require, you will still have the same issue. – Justin E Apr 11 '14 at 15:25
  • @whitelettersandblankspaces Could be a directory-separator issue between windows and linux, see for example here: http://stackoverflow.com/questions/4178263/make-a-path-work-both-on-linux-and-windows – jeroen Apr 11 '14 at 15:29
  • https://stackoverflow.com/questions/18966889/how-can-i-make-require-once-fetch-a-file-from-the-directory-above?rq=1 Mark B says it well: `"require/include are NOT bound by the webserver's document root. That's a concept that exists only in the webserver. PHP sees only the filesystem, and can access any file/directory on it that its containing user ID has access to."` – Justin E Apr 11 '14 at 15:32
1

Try just:

require_once '../Renderer.php';
MrHunter
  • 1,892
  • 1
  • 15
  • 23
  • Thank you for your time, unfortunately, this doesnt resolve the problem – Adib Aroui Apr 11 '14 at 15:07
  • Hmmm, and you can verify `Renderer.php` is here: `/home2/attafsir/public_html/balaghatoalquran/production/wp-content/themes/twentyten/Text/Diff/Renderer.php` ? – MrHunter Apr 11 '14 at 15:08
  • according to my file manager in hosting account, the location of file is exact and the file exists there – Adib Aroui Apr 11 '14 at 15:09
  • @whitelettersandblankspaces In a hosting account / is the root of your account, your files may be in public_html httpdocs etc. Who do you use for hosting? – Justin E Apr 11 '14 at 15:23
0

You can't use '/../Renderer.php'. It's either '../' which refers to one folder up or '/' which refers to root directory.

Santosh Achari
  • 2,936
  • 7
  • 30
  • 52
0

Remove the first slash and try either:

require_once '../Renderer.php';

Or

require_once '../../Renderer.php';

Which one works depends on your file structure.

Bradley
  • 490
  • 3
  • 9
  • unfortunately, this is not working. only `require_once '/../Renderer.php';` that works but only on localhost – Adib Aroui Apr 11 '14 at 15:08
0

require_once DRI . '/../Renderer.php';

-1

I am faceing same problem enter image description hereChange your Current version PHP to PHP 5.3