Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

noob php question

Status
Not open for further replies.

verbatim1

Programmer
Apr 18, 2005
58
US
f i want a variable to = the name of the folder the script is placed in, how would i write that?

script is in : /var/
and i want the username to be 'joe'


any help offered is appreciated.
 
hm try something like this

$mypath = pathinfo($_SERVER['SCRIPT_FILENAME']);
echo substr(strrchr($mypath["dirname"], "/"), 1);


gry online
 
sorry for explaining it wrong.

what i meant to say was, if thephp file is in a folder called 'joe'

how can i make a script that says $username = this folder

so that if the folder is 'joe' - $username = joe
will appear.

or if the folder the script is in is melissa
$username = melissa
 
Assuming the username is being passed by a field named "username" in a submitted form:

<?php
$username = $_POST['username'];
$path = "/var/
if(isset($username)){
echo "The path to the directory is ".$path; }
?>

<FORM METHOD="POST" ACTION="test.php">
<input type="text" name="username" size="10">
<input type="submit" value="Submit"></form>



should work. You'll need to verify the directory exists before trying to open any files in that directory of course.

IamStang
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top