Current Working directory

Reply

Join Date: Jun 2007
Posts: 1,492
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Current Working directory

 
0
  #1
Feb 21st, 2009
Hi All,
I'm using XAMMP server in USB stick and have Web project in this structure:
F:\xampplite\htdocs\projects\Elijah

So my current working DIR is elijah. However, I don't want to write the long path "../projects/elijah/elijah.css" when linking css file or using images. I would like to use something like a function that will retrieve current working directory so that path will be
"The_function_to_get_DIR/elijah.css" I want the root to be seen virtually as elijah

Thanks for your help, and I'm ready to clarify wherever there's ambiguity
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,397
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is online now Online
Nearly a Posting Virtuoso

Re: Current Working directory

 
0
  #2
Feb 21st, 2009
  1. include("./thisfile");
  1. <link rel="stylesheet" type="text/css" media="screen" href="./style.css">
  1. $basedir=substr("$_SERVER['SCRIPT_FILENAME']",0,strripos("$_SERVER['SCRIPT_FILENAME'],"/",0));
  2.  
just some of the diff ways to find the same thing
Last edited by almostbob; Feb 21st, 2009 at 3:50 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,492
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Current Working directory

 
0
  #3
Feb 21st, 2009
Can you comment on code so as I ca understand better
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,397
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is online now Online
Nearly a Posting Virtuoso

Re: Current Working directory

 
1
  #4
Feb 21st, 2009
Originally Posted by evstevemd View Post
Can you comment on code so as I ca understand better
First two, . is the default for current folder, as .. is parent
third one

take the current script name as known to the server and break it at the last / character
substring of the server array, from position 0 to the position of the last /
this gives the documentroot path to the current folder
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,492
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Current Working directory

 
0
  #5
Feb 22nd, 2009
Ok I have this code:
How do I link the CSS file using PHP in that, Instead of full CSS path I will have href="$paths/elijah.css" ?

Thanks for your valuable reply

  1. html>
  2. <head>
  3. <title>Test Page - Elijah Ministries</title>
  4. <?php
  5. $paths = getcwd();
  6. print $paths;
  7. ?>
  8. <link rel = "sheet" style = "text/css" href = "/project/elijah/elijah.css" />
  9. </head>
  10.  
  11. <body>
  12. <table width="100%" height="450px" bgcolor="silver">
  13. <tr>
  14. <td class="top_header">
  15.  
  16. </td>
  17. </tr>
  18. </table>
  19.  
  20.  
  21. </body>
  22.  
  23. <html>
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,492
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Current Working directory

 
0
  #6
Feb 23rd, 2009
May be question was too vague, here is another way,
I get path of current DIR via php script
  1. <?php
  2. $paths = getcwd();
  3. ?>

Then I want to use this path when linking all my image and css file
Here is my code linking the CSS file
  1. <link rel = "sheet" style = "text/css" href = "/project/elijah/elijah.css" />

How do I link the CSS file using $paths that is <link rel = "sheet" style = "text/css" href = "$paths/elijah.css" />

Thanks for your invaluable help
Last edited by peter_budo; Feb 25th, 2009 at 8:04 pm. Reason: Closing tag is [/code] not [/php]
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,397
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is online now Online
Nearly a Posting Virtuoso

Re: Current Working directory

 
0
  #7
Feb 23rd, 2009
Your code
  1. <link rel = "sheet" style = "text/css" href = "/project/elijah/elijah.css" />
shouild be
  1. <link rel="stylesheet" type="text/css" href="/project/elijah/elijah.css" />
even before you make it
  1. <link rel="stylesheet" type="text/css" href="./elijah.css" />
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,492
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Current Working directory

 
0
  #8
Feb 23rd, 2009
Yeah, that error is obvious, but I failed to see it. Thanks.
It is that I'm refactoring my old HTML code to incorporate PHP. However, My working folder in XAMPP ("/project/elijah/elijah.css") will not be valid when kept on server where path will be something like "/elijah.css". So I want to use path to avoid changing things in file, which is tedious work
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 873 | Replies: 7
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC