I decided I was going to play with defining a constant and then using the constant to include almost every file so that the folder could be placed anywhere (preferably outside public_html) I am defining the directory as a constant Like:
and when I call a file it is like so
So I spent the last two weeks completely rewriting the script on my server while updating it and it works GREAT!!! The problem however is migrating from server to server. On my home server the the back slashes “\” work just like they should. On Server 2 the constant (DIR) changes the backslashes to forward slashes “/” and throws an error. I end up with something like
So i did what any smart man would do (i thought)
First I used string replace before defining the constant and changed the slashes. Still errors.
So i get smarter and use find/replace to go through and change all of my hard coded backslashes to forward slashes. Now the main page loads but when I make a selection I get an error again. I double and triple checked the error displayed, the correct file is being queried but the server says it is not there or failed to include.
It really should not matter if you have forward or back slashes. PHP will usually compensate. You might have something else going on that obscures the problem.
Make a simple file called test.php in your public_html with something like:
Thats what I thought, defining the directory should have solved my problems. I was wrong.
My Server will not include a file that isn’t written properly.
IE /home/user/public_html/folder\folder2\file.php will not work.
Error reporting is on thats how I am positive it is calling the right directory.
As I stated above I get the index page to load properly after changing the slashes. But now when I select a link it says the file is not there.
IE: (an actual error statement)
Warning: include(/home/user/public_html/folder/folder2/file.php) [function.include]: failed to open stream: No such file or directory in /home/user/public_html/folder/folder3/file.php on line 21
maybe a server setting? i seriously just dont get it
Yes I created a sample page, many of them and even another one more time before responding to your post just to double check I wasn’t doing something silly.
Yes index.php is my home page and it calls the file that defines the constant and then loads the rest of the php via the include statement with the defined DIR <<< so half of it is working. the problem now seems to be calling the rest of the files if they are contained within a function
the rest of the function
By selecting a link a mean a valid link that the index.php produces in the menu. The link is what it should be I verified it, the template loads, but the includes and functions throw an error.
and they are using the same include (DIR.“/folder/file.php”); that loaded the first set of functions on the index.php
just thought I might add I am not a copy paste coder and I am not looking for some one else to write my code, I already wrote it and have a working version on my windows server. My linux server is what I am having a problem with. even though I see what directory is being searched for the file by the error thrown and I know the slashes are currently correct I plan on trying Anthony’s suggestion in the morning. DIRECTORY_SEPARATOR
Is there any reason at all, the server would use the defined directory correct the first time but not if it is called in a second “layer”? i am really trying to stay away from putting all files in the same folder if I can
The error message you posted showed your folders under public_html. Is this really the case? All I can think of is a permission problem under linux. But if they are under public_html then the web user should be able to find them. I assume you checked their read permission. Can you run your test scripts from the command line?
Is it your own linux box or a shared host? /home/user/public_html seems a bit strange. I would have expected a user specific directory there.
Your original post had:
Which contains a typo. I’m sure it has been fixed in the code you are running.
All I can suggest is that you paste an exact copy of the relevant portions of index.php, folder2/file.php, folder3/file.php
I’m thinking you still have a simple typo somewhere or we are not understanding exactly what you are trying to do. Grasping for straws.
One more thing - linux file names are case sensitive, windows are not.
Yes there was a typo in the post, i hand type not copy and paste I am sorry. I would much rather have the folder above the public_html which is why I wrote the file script way, I moved it to public_html for troubleshooting and will move it back to where it belongs once I fix this error.
I was always told to not display errors and definitely don’t display them for the world to see, but here goes.
Warning: include(/home/memory/public_html/XXX/DB/dbGetProductInfo.php) [function.include]: failed to open stream: No such file or directory in /home/memory/public_html/XXX/Function/update-products.php on line 1
I have no idea why but when I FTP’d my files from my pc to the server for some reason it kept changing the file name from
I couldn’t change the file name with FTP or file manager after I changed the file name it would revert back to dbgetProductInfo.php for some reason, the fix so far was to upload both files dbGetProductInfo and dbgetProductInfo but if I delete dbgetProductInfo dbGetProductInfo Reverts Back to dbgetProductInfo for some reason
I still haven’t figured out why(yet) but I am happy it’s working now I can get back to updating the overall script. Thanks again ahundiak