alex121 Posted May 17, 2009 Posted May 17, 2009 Hi, Hope someone can help, i am still learning PHP but have only got the basics so far, enough to install contributions and make general layout alterations, but would like to setup sub folders to save pages to so that the site does not get too messy. My problem is that i can get the pages to work when they are saved in the root but if i try to save them in a folder ie pages/pages1.php i keep getting the following errors: that includes/appliction_top.php file does not exist, even though i have tried to change the links to the right locations. root/page1.php works fine root/pages/page1.php does not its so frustrating Any help or ideas would be great TIA Alex
♥FWR Media Posted May 17, 2009 Posted May 17, 2009 Hi,Hope someone can help, i am still learning PHP but have only got the basics so far, enough to install contributions and make general layout alterations, but would like to setup sub folders to save pages to so that the site does not get too messy. My problem is that i can get the pages to work when they are saved in the root but if i try to save them in a folder ie pages/pages1.php i keep getting the following errors: that includes/appliction_top.php file does not exist, even though i have tried to change the links to the right locations. root/page1.php works fine root/pages/page1.php does not its so frustrating Any help or ideas would be great TIA Alex alex Paths can be a bit of a nightmare when you are starting out, unless you give a full path. In osCommerce application_top.php is always called via a file in root it can therefore be called using a relative path .. require('includes/application_top.php'); This path is relative to root. To include the same file outside of root one method is to to change the working directory. chdir('../'); require('includes/application_top.php'); chdir('../'); took you back one directory so from root/pages/ to root/ Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
alex121 Posted May 17, 2009 Author Posted May 17, 2009 Thanks for being so quick. One question though, Do i have to put " chdir('../'); " infront of every includes and require link in each page? TIA Alex PS I only ask as my page has gone haywire although it now displays everything
alex121 Posted May 17, 2009 Author Posted May 17, 2009 I have sort of got round it as i have had to create another stylesheet.css file and put it in the same folder for some reason i cannot use the same file as there are graphical links which dont seem to like the full location address but it is something i can get over as it is only on my testing server, plenty of room to make mistakes. Thanks for you help
alex121 Posted May 25, 2009 Author Posted May 25, 2009 I have got round the stylesheet problem by placing the full path in the code, but my next problem is linking to the sub directory page. Thanks to FWR Media who put me right with the 'CHDIR' command. This work fine and i can go directly to the page by typing the address into the address bar, my problem is that my links box not link to the right page. Here is what i have: my main site which has the OSC files etc. In the main site there is a sub site which is in a folder called shop which has the OCS files. This works great as i have a main site which uses the database for specials boxes, whats new boxes banners etc plus my main site. From here in my links column, i can link to all the other pages and to the shop site. These files are linked from the includes/filenames.php and the relative code link is define('FILENAME_SHOP_INDEX', 'shop/index.php'); This works as it has it's own includes folder and other necessary OSC files. Problem is when i want to do the following: define('FILENAME_PCTOOLS, 'more/pctools.php'); when i hover over the link, the display shows that it is missing the sub directory and will not link to it. I have tried various ideas and none work. Can someone please help as i know it is probably a simple solution TIA Alex
alex121 Posted May 31, 2009 Author Posted May 31, 2009 Hi, I have been scrathing my head over this for the past week or so, but still dont have an answer. Here is what i hve done so far: i have created a folder called customers. In this folder is a file called customers.php. Thanks to FWR Media who put me right with the 'CHDIR' command. This means that my page shows up fine. The problem i still have is that i have a links box,a modified version if the information box. All the links in this box work fine, until i try to link into the sub directory. i have used the following line at the end of the section: '<a href="' . tep_href_link(FILENAME_CUSTOMERS) . '">' . BOX_INFORMATION_CUSTOMERS . '</a>'); so far what i have worked out is to link to the sub directory, in the 'includes\filenames.php' folder, if i use the following line: 'define('FILENAME_CUSTOMERS', 'customers/customers.php');'. When i hover over the link i get the full path testingserver/customers/customers.php?osCsid=78(session id). When i click on it i get the following errors: 'Warning: require(includes/languages/english/customers/customers.php) [function.require]: failed to open stream: No such file or directory in /var/www/bccdual/customers/customers.php on line 16 Fatal error: require() [function.require]: Failed opening required 'includes/languages/english/customers/customers.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/bccdual/customers/customers.php on line 16' If i use the following line in the 'includes\filenames.php' folder, 'define('FILENAME_CUSTOMERS', 'customers.php');', and then When i hover over the link i get the full path 'testingserver/customers.php?osCsid=78(session id)', but when i click on the link i get the HTTP 404 page not found error. However if i manually type in the full path to the page it works! I hope that someone has a few ideas! as its driving me up the wall. It is only intended to tidy up the file system so that i can find files. I hope i might have explained myself a bit better this time round TIA Alex A quick note: I can use the full path 'testingserver/customers/customers.php'. This does work fine, but it tends to upset the layout.
MrPhil Posted May 31, 2009 Posted May 31, 2009 You should never have to use chdir('../'); require() and include() statements use the PHP (system) path. A relative path starts with anything other than /. It is relative to whatever directory the currently executing script is in. To start with a directory name: require ('includes/application_top.php'); is the same as require ('./includes/application_top.php'); ./ means "from this directory", while ../ means "from my parent directory". Starting with a slash / is an "absolute path", but that means different things to HTML and to PHP. For HTML, the "root" directory (/) is whatever directory is topmost within your site -- the directory pointed to by http://www.yoursite.com. For PHP, the root directory is the filesystem's root. If you start with /, you need to give the full path, e.g., /var/www/bccdual/customers/customers.php. I believe that CSS follows the HTML model. Note that "current directory" within a CSS file is the directory that the CSS file is found in, not the directory that the executing page or script is in. It's generally easier to use only relative paths in CSS. If you are in /var/www/bccdual/customers/customers.php and trying to require ('includes/languages/english/customers/customers.php');, that's saying that "includes/" is under "customers/", i.e., the full path is /var/www/bccdual/customers/includes/languages/english/customers/customers.php. Is that a correct path?
alex121 Posted June 2, 2009 Author Posted June 2, 2009 You should never have to use chdir('../'); require() and include() statements use the PHP (system) path. A relative path starts with anything other than /. It is relative to whatever directory the currently executing script is in. To start with a directory name: require ('includes/application_top.php'); is the same as require ('./includes/application_top.php'); ./ means "from this directory", while ../ means "from my parent directory". Starting with a slash / is an "absolute path", but that means different things to HTML and to PHP. For HTML, the "root" directory (/) is whatever directory is topmost within your site -- the directory pointed to by http://www.yoursite.com. For PHP, the root directory is the filesystem's root. If you start with /, you need to give the full path, e.g., /var/www/bccdual/customers/customers.php. I believe that CSS follows the HTML model. Note that "current directory" within a CSS file is the directory that the CSS file is found in, not the directory that the executing page or script is in. It's generally easier to use only relative paths in CSS. If you are in /var/www/bccdual/customers/customers.php and trying to require ('includes/languages/english/customers/customers.php');, that's saying that "includes/" is under "customers/", i.e., the full path is /var/www/bccdual/customers/includes/languages/english/customers/customers.php. Is that a correct path? Hi MrPhil, Thanks for your reply but i dont quite understand what you are getting at :huh: I dont think that i may have explained my problem properly. The situation is this, my whole site is within the root of the site, (currently on a testing server), ie: www.mysite.com/index.php so all the files are in the OSC file structure. What i am trying to achive is to group custom files into their own folders. Mainly to tidy up the file structure. On advice from FWR Media, using chdir('../'); above the following line require ('includes/application_top.php'); made my custom files appear and work fine when they are in a sub folder like customers which has the custmoers.php file in it. Without the chdir('../'); i get the following errors: Warning: require(includes/application_top.php) [function.require]: failed to open stream: No such file or directory in /var/www/bccdual/customers/customers.php on line 14 Fatal error: require() [function.require]: Failed opening required 'includes/application_top.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/bccdual/customers/customers.php on line 14 when i use the chdir('../'); command the page appears and works fine. My problem is the links to the file. This is my big headache. If i use a full path link, ie: /var/www/bccdual/customers/customers.php but this upsets the session id, i have read in a post quite sometime ago that it tends to confuse the system a bit, or something like that, i may have misread it. TIA Alex
♥FWR Media Posted June 2, 2009 Posted June 2, 2009 My problem is the links to the file. This is my big headache.If i use a full path link, ie: /var/www/bccdual/customers/customers.php but this upsets the session id, i have read in a post quite sometime ago that it tends to confuse the system a bit, or something like that, i may have misread it. Sessions have nothing at all to do with include paths. Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
alex121 Posted June 2, 2009 Author Posted June 2, 2009 Sessions have nothing at all to do with include paths. Thanks, that is something i can ignore and not worry about, but it still does not solve my initial problem. Using the following piece of code in the links box '<a href="' . tep_href_link(FILENAME_CUSTOMERS) . '">' . BOX_INFORMATION_CUSTOMERS . '</a>'); although the layout looks fine and in line with the rest of the links it still creates the following problem, as i said in an earlier post, post 6. so far what i have worked out is to link to the sub directory, in the 'includes\filenames.php' folder, if i use the following line: 'define('FILENAME_CUSTOMERS', 'customers/customers.php');'. When i hover over the link i get the full path testingserver/customers/customers.php?osCsid=78(session id). When i click on it i get the following errors: 'Warning: require(includes/languages/english/customers/customers.php) [function.require]: failed to open stream: No such file or directory in /var/www/bccdual/customers/customers.php on line 16 Fatal error: require() [function.require]: Failed opening required 'includes/languages/english/customers/customers.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/bccdual/customers/customers.php on line 16' If i use the following line in the 'includes\filenames.php' folder, 'define('FILENAME_CUSTOMERS', 'customers.php');', and then When i hover over the link i get the full path 'testingserver/customers.php?osCsid=78(session id)', but when i click on the link i get the HTTP 404 page not found error. However if i manually type in the full path to the page it works! Thanks for all you help and patience! its me not fully understanding :blush: TIA Alex
Recommended Posts
Archived
This topic is now archived and is closed to further replies.