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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble passing directory info

Status
Not open for further replies.

IamStang

Technical User
Feb 12, 2005
27
0
0
US
I have a problem that I hope someone can help me out with. I need to write a variable like the one below to a file. Currently, I am trying to do this similar to as shown below, to no avail:
Code:
$dirPath = "C:\script_pages\myPHPscript\";
$userName = "Bob"; //Could be anything.

$EmpHTMLFile = "my_data.txt";
	$Emp_html = fopen($EmpHTMLFile, "a");
	fwrite($Emp_html, $dirPath."/".$userName.".html\n");
	fclose($Emp_html);

The code above simply writes "Bob.html" in the file without the directory path. Granted, the backslash(\) is generally used for other purposes in PHP. So, I changed them to foward slashes with no luck either.

If I change
Code:
fwrite($Emp_html, $dirPath."/".$userName.".html\n");
to
Code:
fwrite($Emp_html, "C:/script_pages/myPHPscript/".$userName.".html\n");
It works fine.

Is there a way to pass the directory path via a variable? Similar to my first attempt?

Thanks!
IamStang
 
Eventually change
$dirPath = "C:\script_pages\myPHPscript\";
to
$dirPath = "C:/script_pages/myPHPscript/";

you have to decide :
- have to use / (slash)
- or \ (backslash) , better escaped slash: \\ "C:\script_pages\myPHPscript\"

In a mixed sentence, like
$dirPath = "C:\script_pages\myPHPscript\";
...
fwrite($Emp_html, $dirPath."/".$userName.".html\n");

the result is ambiguous.



PM


___
____
 
Thanks!

I figured it out using the dirname() function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top