Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3032
| From | sheldonlg <sheldonlg@thevillages.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: fopen Problem |
| Date | 2011-08-31 08:59 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <j3lblm$tik$1@dont-email.me> (permalink) |
| References | (1 earlier) <j3endc$2cg$1@dont-email.me> <3kvl57p37b8r2p3rhicarjbkssj8e8ci8n@4ax.com> <j3jtpr$cs9$1@dont-email.me> <j3l3l4$ehp$1@gregory.bnet.hr> <j3l5h2$mq3$1@dont-email.me> |
On 8/31/2011 7:22 AM, Jerry Stuckle wrote: > On 8/31/2011 6:49 AM, A wrote: >>> $_SERVER['DOCUMENT_ROOT'] . '/logbooks/CAA001/blahblah.txt'. >>> >>> dirname(__FILE__) is a very bad way to to it - it is dependent on the >>> location of the script opening the file and will break if you move the >>> script to a different directory. >> >> if I understood the question correctly the file is *NOT* on his own >> server >> because he allow_url_fopen configuration setting. >> dirname(__FILE__) is very useful. I tend to keep all my scripts in a >> relative file/folder structure so I WANT to move them and keep the paths >> properly in place. >> >> > > Whether it is his own server or not is immaterial as it has no effect on > my statement. > > And obviously you have not tried $_SERVER['DOCUMENT_ROOT'] = which also > allows you to keep your scripts in a file/folder structure. The > difference being dirname(__FILE__) changes depending on the calling > script's location = move the calling script and your code breaks. > > For this reason it's a bad idea to use it to access other files unless > that file is *totally dependent* on the calling script and will *always* > be in the same relative location to the calling script. But such > assumptions also make the files more tightly coupled, creating > unnecessary dependencies. > > $_SERVER['DOCUMENT_ROOT'] always points at the root directory of the > website and is independent of the calling script's location. > If you, like most people, move a file it is not only that single file. It is a whole directory tree. Using $_SERVER['DOCUMENT_ROOT'] would then break the code whereas dirname(__FILE__) would not. I don't know about you, but I don't just wake up one morning and say "gee, I think I'll move that file". If I move anything, it is an entire directory tree. If I have to move just a single file, I do a grep for that filename and I also look inside that file for dependencies. How about you? -- Shelly
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
fopen Problem Call Me Tom <noemail@nowhere.com> - 2011-08-28 20:21 -0400
Re: fopen Problem Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-28 20:43 -0400
Re: fopen Problem Richard Damon <news.x.richarddamon@xoxy.net> - 2011-08-28 20:44 -0400
Re: fopen Problem Call Me Tom <noemail@nowhere.com> - 2011-08-28 23:04 -0400
Re: fopen Problem Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-28 23:09 -0400
Re: fopen Problem Call Me Tom <noemail@nowhere.com> - 2011-08-29 00:19 -0400
Re: fopen Problem Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-29 07:36 -0400
Re: fopen Problem Call Me Tom <noemail@nowhere.com> - 2011-08-29 19:15 -0400
Re: fopen Problem "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-08-29 13:37 +0200
Re: fopen Problem sheldonlg <sheldonlg@thevillages.net> - 2011-08-30 19:30 -0400
Re: fopen Problem Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-30 20:04 -0400
Re: fopen Problem "A" <a@a.a> - 2011-08-31 12:49 +0200
Re: fopen Problem Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-31 07:22 -0400
Re: fopen Problem sheldonlg <sheldonlg@thevillages.net> - 2011-08-31 08:59 -0400
Re: fopen Problem Jerry Stuckle <jstucklex@attglobal.net> - 2011-08-31 13:39 -0400
Re: fopen Problem "A" <a@a.a> - 2011-08-29 22:45 +0200
csiph-web