473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Save file at the same place as an included script

I've got a script to access my database called mysql.class.php. So from every other script that is talking to the database, this file i included, like this for instance:

[PHP]<?php
include("../classes/mysql.class.php");
//Code using the included file goes here
?>[/PHP]

Now I want the file mysql.class.php to save a log-info for every query in a file that is placed in the same folder as the mysql.class.php-file. However, the file is saved where the script which included mysql.class.php is located.

How can I always save the file at the same place as mysql.class.php, even though it's included in another folder?
Oct 31 '08 #1
3 1673
Markus
6,050 Expert 4TB
Can you not just point to the folder the same way you do with the include?
Oct 31 '08 #2
Atli
5,058 Expert 4TB
Personally, I would probably just set a constant that is pointed to the absolute location of the directory.

For example, if this were my index.php file:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // The absolute path where the index file is
  3. define("LOC_ROOT_DIR", "/path/to/my/project/");
  4.  
  5. // The absolute path to the class directory
  6. define("LOC_CLASS_DIR", LOC_ROOT_DIR . "classes/");
  7.  
  8. // Include the file.
  9. include(LOC_CLASS_DIR ."class.mysql.php");
  10.  
  11. // Do whatever else you want with it here...
  12. ?>
  13.  
And in my "class.mysql.php" file, I might do:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // After whatever you want logged, you could do:
  3. file_put_contents(LOC_CLASS_DIR . "log.txt", $logText);
  4. ?>
  5.  
Now, all you have to do is change the LOC_ROOT_DIR constant whenever you set this up on a new server (which usually doesn't happen that often) and you can use it in any script without having to worry about where the script is actually located.
Nov 1 '08 #3
Since I include the file from different locations, I can't do it the same way I do with the include...All paths are realative.

I could use a constant, but that's trouble when I'm uploading the site - and I do that quite often to fix bugs...
Nov 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Randell D. | last post by:
Folks, I've found a nice menu piece of javascript that works fine when the code is included entirely inside the html page. However, when I place the javascript code outside, in its own ".js"...
3
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place...
10
by: Prakashsir | last post by:
I have desgined script to show div at runtime. Now I want to copy that newly created div and/or to save in normal html file so that i can see later. 1. When I select all the content or view its...
1
by: Ryan Moore | last post by:
I'm trying to make a page that, when opened, displays a file save dialog, then closes itself (essentially just leaving the file save dialog). Is this possible? I've tried this: ...
4
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. ...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.