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

save txt files to folders

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
if i want to save a txt file to the server by using php i normally write:

if ($file=fopen("usernumber.txt", "w")) {


fwrite ($file, "text=$x");

the file usernumber.txt is written
but i want this file to be written in a folder called users,
what should i write then /users/usernumber.txt ???

Thx
 
Yes, that will work, along with you could use PHP's chdir() function to change the current directory to the users directory.

Like so:

[tt]
chdir("users");
[/tt]

Will change to the users directory. Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
 
Be careful!

If you use /users/usernumber.txt, you are telling PHP to write the file usernumber.txt in a folder called users under the root location instead of your document root.

If you are looking to save the file in a folder called users within your document root (say you have all of your web site content under /home/site/, you could do one of the two methods:

Code:
if ($file=fopen("/home/site/users/usernumber.txt", "w")) {
     fwrite ($file, "text=$x");
}

or

Code:
if ($file=fopen($DOCUMENT_ROOT."/users/usernumber.txt", "w")) {
     fwrite ($file, "text=$x");
}

Sincerely,
Chad. ICQ: 54380631
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top