Paths are working on localhost but not on server - php

This is structure I have. Page add-product.php is in folder public_html. Partial page ConnectQuery.php I need to access is in folder partial.
My project worked fine on localhost with wamp. Now I uploaded it to server and pathing got screwed.
Error I get:
Warning: include(/storage/ssd3/728/17657728/public_html/partial/ConnectQuery.php): failed to open stream: No such file or directory in /storage/ssd3/728/17657728/public_html/add-product.php on line 13
Line 13 in add-product.php is
include __DIR__ . "/partial/ConnectQuery.php";
EDIT: There is one more error
Warning: include(): Failed opening '/storage/ssd4/729/17661729/public_html/partial/ConnectQuery.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /storage/ssd4/729/17661729/public_html/add-product.php on line 13

usually paths never work the same way unless the development machine and server OS are same and they handle directories and files the same way -
Say if your development machine is Windows your Drive C:// will be there
its not the same in case of Linux and most of the servers are on linux and hence you're facing paths issue try using a path library in your case
in Node js there is path ;
which will point to current directory from you're running your project and from there on the paths will work with no issues .

Check the case in the spelling of the filename ConnectQuery.php.
Is it maybe connectQuery.php (like you wrote in another question)? Or connectquery.php?
Windows ignores differences in the case of file names, Linux doesn't.

If you are using PHP <= 5.2 than you have to try as below
$dir = dirname(FILE);
include($dir.'/partial/ConnectQuery.php');
Please try this and if you using some other php version than mention it here

I used to have problems with includes in my PHP projects between localhost and the actual server. I was able to get rid of this by using dirname(__FILE__). In your case you would use the following in your add-product.php
include dirname(__FILE__)."/partial/ConnectQuery.php";
This bypasses some weird standard include path errors by providing the full path of the current files directory.

I think this is all caused by directory separator issue.

Check the case of the ConnectQuery.php filename.
Windows is case-insensitive which means that WAMP will find a file named connectquery.php even if you requested CONNECTQUERY.php
Linux won't. If you request a file named CONNECTQUERY.php, it will search for this exact filename.
I advise you to adopt a convention : only lower-case letters for filenames. This will save you a lot of headaches.

Related

Why isn't PHP.ini include_path working correctly for me here?

I'm experiencing some weirdness trying to setup PEAR on my development machine (Windows XP).
The process is simple enough and everything makes sense, but I'm trying to use one of the installed packages which calls on the PEAR.php file and am getting:
Failed opening required 'PEAR.php' (include_path='.;C:\Program Files\PHP\PEAR')
It's a pretty straightforward error to get assuming the file/path doesn't exist, except I've checked and double checked - it absolutely does - right down to capitalisation (which I know doesn't matter on Windows normally but still...)
What can I possibly have overlooked that means the file can't be opening?
Just to re-iterate, the file/dir DEFINITELY exists as C:\Program Files\PHP\PEAR\PEAR.php - and I have also tried:
forward slashes
short dir names (Progra~1)
all lower case (even though the files are as is) and even setting the include path to
ONLY that directory.
test.php in same directory
test.php in c:\ and with include path set to c:\ and just \
PHP (5.2.6) is NOT running in safe mode, and the web server is Apache 2.
Maybe your php configuration has open_basedir set? If so, set it's value to none.
Try one of these:
C:/Program\ Files/PHP/PEAR/PEAR.php
C:/Program Files/PHP/PEAR/PEAR.php

XAMPP WIN 7 Cache Directory Isn't writeable

I get the following error message when i try to run some php code on a site I have built in XAMPP
Error 0: Cache directory 'C:\xampp\htdocs\eve-charinfo/.pheal-cache/722091/n3Yeskd6U90NyJXG5m5O6p5Rid9NVKKfJBaSVx3j9S3xApfAiYhBBSabzZas7VCr/account/APIKeyInfo/' isn't writeable
"Pheal is a PHP library for accessing the EVE API, its basically a PHP port of EAAL it uses some metaprogramming foo to ensure it does not need changes when the EVE API is changed. it also contains a simple file cache that can respects the EVE APIs cache timers."
Somewhere in your PHP code will be a line that looks like this ....
PhealConfig::getInstance()->cache = new PhealFileCache('/your/path/to/the/cache/');
Make sure this is a valid windows directory.
Check you have write access to the directory. If its in a webroot
directory you probably dont.
Make sure the full path starts and ends with a '/' character Use a *NIX like file
path, not a DOS type i.e. use '/' as a directory separator
Do not include the C: drive directive
Probably best not to use a '.' in a windows file path but will likely
still work
And of course, your best source of answers about pheal is the EvE online Technology forum.

Linux: File both exists and not exists

I am writing a PHP application, and I've just encountered a really wierd error. After a recent move to a new (Ubuntu) server, i started getting fatal errors on a require_once statement. So obviously the file doesn't exist, or the file permissions are wrong, right?
No, as it turns out:
The file does exist
The file is checked out from an SVN repository. When I go into the folder and list the files (ls or ls -l) the file is clearly there and has the correct file size. When I update the file in the repository and update the working copy, the changes are copied to the working copy. The file has permissions 755, so everyone should be able so see and read it. Other files in the same directory are working just fine.
The file also doesn't exist:
PHP exits with a fatal error because the file can't be found. If I use the find-command, the file is not found. If I try to use nano to edit the file, it claims it does not exist. If I start typing the filename and press tab to autocomplete, it can't find the file.
This behaviour has now happened on two separate servers, but it works fine on a third server. All the servers run Ubuntu 10.04.
Does anyone have any idea what is going on?
EDIT:
File name is AdminIpv4RangeAddFormHandler.inc.
Full error message, with file paths obscured:
Warning: require_once(fullpath/AdminIpv4RangeAddFormHandler.inc): failed to open
stream: No such file or directory in fullpath/anotherfile.inc on line 34 Fatal error:
require_once(): Failed opening required 'fullpath/AdminIpv4RangeAddFormHandler.inc'
(include_path='.:/usr/share/php:/usr/share/pear') in fullpath/anotherfile.inc on line
34
The following command produces no output:
find -name AdminIpv4RangeAddFormHandler.inc -ls
A regular ls -li outputs (amongst others) this row:
2233407 -rwxr-xr-x 1 root root 1597 2011-12-13 08:02 AdminIPv4RangeAddFormHandler.inc
Be careful switching OS's, as some are case sensitive, and others aren't.
I use my Mac for development (case insensitive), so it doesn't matter what casing I use for file_exists() or include_once() etc. Then I deployed to Ubuntu 11 (case sensitive), and all my includes stopped working. I suspect you have the same exact problem.
The tricky part for me was, while using git, my version control didn't detect changes in file name case as a modification. I actually had to rename every file with some sort of prefix, commit and deploy, rename them back to what they should be (with consistent capitalization!), and finally commit and deploy again. It was a complete pain.
Moral of the story--code for your production system, not your dev system.
Take a good long look at your filenames:
AdminIpv4RangeAddFormHandler # from PHP
AdminIpv4RangeAddFormHandler # from find command
AdminIPv4RangeAddFormHandler # from ls output
^
You should pick IP or Ip and stick with the decision everywhere.

Scandir fails to open directory

$contentdirectory = '/dead-wave/dead-wave_content';
$contentlaunch = scandir($contentdirectory);
that's what I'm using to create an array from which I echo it's values using a for each statement. this works perfectly on my dedicated server, but once hosted on godaddy servers returns an error message 'failed to open dir: No such file or directory in...' now the directory path is certainly correct the actual problem is unknown to me. Any Thoughts?
Are you sure the path is correct? If the path is a subdirectory of your current directory, you should use 'dead-wave/dead-wave_content' instead of '/dead-wave/dead-wave_content'.
are you sure the path is correct? on a hosting you are usually rooted to a different directory (like /home/user1).
So the Path from above would be /home/user1/dead-wave/dead-wave_content/
you can do a
exec('pwd',$return);
print_r($return);
to find out where you actually are.
I'm not sure this is the same problem you're having but sometimes I can't use any file i/o functions when I'm running unit tests on top of Zend Server via Zend Studio even though they worked on Apache.
I think you need to rewrite you paths somehow making them relative to the server web directory constant. I'm not sure what that is but I'm sure there is one.
EDIT Oh! I don't think Apache recognizes '/toplevel/secondlevel' path writing style.

Why am I unable to use a variable in my require or include statement on XAMPP?

While cleaning up some old php scripts I've noticed some weird behavior with require/include statements when I try to use variables.
On the live server, the following code works fine..
<?php
$test = "http://localhost/elearning/trunk/mypage.php";
require "$test";
?>
..but on my XAMPP installation ((basic package) version 1.6.7) I receive the following error:
Warning: require() [function.require]: URL file-access is disabled in the server configuration in C:\Documents and Settings\username\Desktop\xampp-win32-1.6.7\xampp\htdocs\elearning\trunk\test.php on line 22
Warning: require(http://localhost/elearning/trunk/mypage.php) [function.require]: failed to open stream: no suitable wrapper could be found in C:\Documents and Settings\username\Desktop\xampp-win32-1.6.7\xampp\htdocs\elearning\trunk\test.php on line 22
Fatal error: require() [function.require]: Failed opening required 'http://localhost/elearning/trunk/mypage.php' (include_path='.;C:\Documents and Settings\username\Desktop\xampp-win32-1.6.7\xampp\php\pear\') in C:\Documents and Settings\username\Desktop\xampp-win32-1.6.7\xampp\htdocs\elearning\trunk\test.php on line 22
If I copy+paste http://localhost/elearning/trunk/mypage.php (directly from the error) into my browser, mypage.php loads. Is this an error in my configuration, or my approach?
You can't use paths that start with http:// on some servers because of security. What you want to use instead is a directory path.
You can get your current directory path by doing something like
echo $_SERVER['DOCUMENT_ROOT'];
that will give you your directory path from the root folder of the server. That is the path you want to use to include/require stuff.
If you didn't quite understand that, try this.
There are two types of paths:
World Wide Web Paths:
http://example.com/directory/file.php
Server Directory Paths:
/home/usr/www/site/html/
The Server directory path is where your files are located on the server's hard drive. Much like your computer's hard drive, it is never changes unless you move the files. On the other hand, The World Wide Web Path (the one everyone uses to access your website) can change based on what domain you are using, where your Document Root is pointing, Mod Rewrites, and more.
Note: The Document Root is the top most directory that your server serves files from. So, if you had index.php in your document root, it would show up like this on the web:
http://example.com/index.php.
When PHP looks for a file, it uses the Server Directory Path, because it is running on the server. When Javascript, which runs from the user computer, wants to look for a file, it uses the World Wide Web path to access it, because it isn't accessing it from the server.
I really hope that somewhere in there, something made sense.
try require "./mypage.php"
not the whole exact directory
PHP isn't smart enough to know that you're including from the same server when you use URL notation like that, so it thinks you're grabbing files from a seperate server (which can be dangerous).
Your server configuration is set to disallow loading these external files (evident by the error message "URL file-access is disabled in the server configuration"), so it's failing.
Since you're on the same server, you can simply use relative paths, like:
require_once 'mypage.php'
Don't use a path like that ... use a relative path or absolute path.
Example
require 'mypage.php'

Categories