galvin Posted September 22, 2010 Share Posted September 22, 2010 I have fopen() code that works fine.. $filename = "trade.php";$filehandle = fopen($filename, 'w') or die("can't open file");fclose($filehandle); But I want it to create the file "trade.php" in a specific directory called "tradepages". I tried changing the one line to be... $filename = ".../tradepages/trade.php"; But that just gives an error saying no such directory exists (even though it definitely does). There has to be a way to create files in whatever folder/directory you want, right? Anyone know how, or what I'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/214120-how-to-fopen-into-a-specific-directory/ Share on other sites More sharing options...
ngreenwood6 Posted September 22, 2010 Share Posted September 22, 2010 Try this: $filename = $_SERVER['DOCUMENT_ROOT']."/tradepages/trade.php";$filehandle = fopen($filename, 'w') or die("can't open file");fclose($filehandle); This is assuming that /tradepages is right off the root of the server if not you will have to adjust. Quote Link to comment https://forums.phpfreaks.com/topic/214120-how-to-fopen-into-a-specific-directory/#findComment-1114176 Share on other sites More sharing options...
galvin Posted September 22, 2010 Author Share Posted September 22, 2010 Worked perfectly, ngreenwood6! Thanks a lot!!!! Quote Link to comment https://forums.phpfreaks.com/topic/214120-how-to-fopen-into-a-specific-directory/#findComment-1114178 Share on other sites More sharing options...
ngreenwood6 Posted September 22, 2010 Share Posted September 22, 2010 np Quote Link to comment https://forums.phpfreaks.com/topic/214120-how-to-fopen-into-a-specific-directory/#findComment-1114180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.