LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-03-2005, 11:09 AM   #1
jfall
Member
 
Registered: Oct 2002
Location: PEI
Distribution: Slackware
Posts: 56

Rep: Reputation: 15
simple php question


All I want to do is get the current directory it's running from and chdir to it

Anyone know the lines to do it?

I know getcwd() will get the dir, but how to I connect that with chdir()

Basically I have a script that I usually add a chdir function to manually, but I want it to be automated (so it works regarldess of which dir the script is in). I need the script to find out what directory it's in and pass that info along to chdir
 
Old 05-03-2005, 02:57 PM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Let me preface this response by saying that I don't know PHP
but if your script is running on a Linux box you can use readlink
(The system call) on /proc/self/exe this will give you the location
of your script eg /home/user/bin/myscript.php. Cut off the file
name and you have your directory to chdir into. I don't know
how PHP deals with system calls so I'm sorry I can't be of more
help.

Edit:
I may just be confused about what you want to do though
because you don't need to chdir into cwd because by
definition cwd is your current working directory. The directory
that you launch the script from and not the directory that the
script is in (unless of course the your cwd is the directory the
script is in).

Last edited by LogicG8; 05-03-2005 at 03:07 PM.
 
  


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
simple apache - php question davespink Linux - Newbie 4 12-28-2005 04:47 PM
Simple PHP Question newuser455 Programming 9 08-28-2005 11:58 PM
Simple PHP question jacksmash Programming 15 03-01-2004 07:00 PM
Simple PHP Question jacksmash Programming 21 01-04-2004 08:31 PM
simple question...where is php.ini taran Linux - Software 3 08-25-2003 01:06 PM

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

All times are GMT -5. The time now is 12:37 PM.

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