nightkarnation Posted August 9, 2010 Share Posted August 9, 2010 Hey guys! I have the following doubt: I have a php file that does the following alongside with other code not displayed here: $fp = fopen("emails.txt", "w"); It opens a txt file called emails.txt that is in the same folder where the php is saved but how do I tell $fp = fopen("/folderbefore/emails.txt", "w"); ?? In other words, how do I write the path on the script that the emails.txt is located in a previous folder where the php file is located?? Thanks in advance for your help Cheers! Link to comment https://forums.phpfreaks.com/topic/210233-fp-fopenemailstxt-w-but-not-in-same-folder-where-php-is-located/ Share on other sites More sharing options...
xangelo Posted August 9, 2010 Share Posted August 9, 2010 ../ That will take you one level above. Just keep adding them for each directory higher you need to go. Your example would be: $fp = fopen("../emails.txt", "w"); Link to comment https://forums.phpfreaks.com/topic/210233-fp-fopenemailstxt-w-but-not-in-same-folder-where-php-is-located/#findComment-1097096 Share on other sites More sharing options...
wildteen88 Posted August 9, 2010 Share Posted August 9, 2010 You can move up on level using ../ $fp = fopen("../emails.txt", "w"); ?? Alternatively use a full path $fp = fopen($_SERVER['DOCUMENT_ROOT'] ."/path/from/root/folder/to/emails.txt", "w"); ?? Link to comment https://forums.phpfreaks.com/topic/210233-fp-fopenemailstxt-w-but-not-in-same-folder-where-php-is-located/#findComment-1097098 Share on other sites More sharing options...
freeloader Posted August 9, 2010 Share Posted August 9, 2010 So if I understand well you want to go up one level? That would be: $fp = fopen("../emails.txt", "w"); edit: common php problems, looks like I've been beaten to it by these other two Link to comment https://forums.phpfreaks.com/topic/210233-fp-fopenemailstxt-w-but-not-in-same-folder-where-php-is-located/#findComment-1097102 Share on other sites More sharing options...
nightkarnation Posted August 9, 2010 Author Share Posted August 9, 2010 Awesome! Thanks a lot guys! Link to comment https://forums.phpfreaks.com/topic/210233-fp-fopenemailstxt-w-but-not-in-same-folder-where-php-is-located/#findComment-1097103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.