LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-06-2005, 07:13 PM   #1
a10waveracer
Member
 
Registered: Mar 2005
Location: Southern Indiana
Distribution: Slackware-current
Posts: 32

Rep: Reputation: 15
How do I use PHP to find a file's directory?


Okay, I am making an installer for a PHP site I am helping work on, and I want the web-installer to automatically detect what the directory is that contains the installer file (ex. if the files was in /web/nuke/install.php, I want it to be able to figure out it is /nuke/ or whatever it may be).

I have tried a couple of different things, but I can never get it to just give me the directory that contains that file.

If anyone could help me with this, I would greatly appreciate it.

Thanks!
 
Old 09-06-2005, 08:01 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
It might be useful to know what you've already tried. Do you plan for the PHP script to work on multiple webservers, or just one? For example, you can get Apache's base directory via apache_getenv and use the pathinfo function on your file, then compare the first and second strings for the answer you're looking for... there is probably an easier way to do it, but I can't see it right now.
 
Old 09-06-2005, 08:59 PM   #3
a10waveracer
Member
 
Registered: Mar 2005
Location: Southern Indiana
Distribution: Slackware-current
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by CroMagnon
It might be useful to know what you've already tried. Do you plan for the PHP script to work on multiple webservers, or just one? For example, you can get Apache's base directory via apache_getenv and use the pathinfo function on your file, then compare the first and second strings for the answer you're looking for... there is probably an easier way to do it, but I can't see it right now.
Yes, I plan on this being used on multiple webservers hopefully, seeing as how this is a open-source project. Basically I have tried some random commands I found on the interwebs, none of them working. The only thing I could really think of doing is somehow pulling the information from the request for the file.... ex. if the url was http://www.google.com/test/install.php, is there a way I could pull out that parent directory with a command of some sort?
 
Old 09-06-2005, 09:08 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
parse_url should be useful. You would still probably need to chop everything from the last '/' with some basic string functions though.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to clear a file's content? iclinux Linux - Newbie 7 03-30-2009 02:01 PM
Help! tar file's name is truncated auden Linux - Newbie 1 03-02-2005 09:09 PM
file's extension??? amanjsingh Linux - Newbie 2 04-17-2004 09:22 AM
Critical system file's. Tarts Linux - Security 16 10-09-2003 10:06 AM
how decode the passwd file's password? yikaikai Linux - Security 10 08-07-2001 04:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration