neridaj Posted December 9, 2008 Share Posted December 9, 2008 Hello, I'm just following some php tutorials regarding file access and can't seem to successfully open a file. Here is what I have: $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); if(!$fp){ echo '<p>There was a problem with your order, sorry!</p>'; exit; } I have an "orders" directory that resides just outside of "/Library/WebServer/Documents/", which is $DOCUMENT_ROOT, is this the correct path? Thanks, Jason Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/ Share on other sites More sharing options...
balistic Posted December 9, 2008 Share Posted December 9, 2008 where is the script being ran from? Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710105 Share on other sites More sharing options...
.josh Posted December 9, 2008 Share Posted December 9, 2008 ../ does not mean document root. It means the folder immediately above the one you're in. Example: http://www.somesite.com/folderA/folderB/folderC/somescript.php inside somescript.php: ../orders.txt is the same as http://www.somesite.com/folderA/folderB/orders.txt ../../orders.txt is the same as http://www.somesite.com/folderA/orders.txt etc... Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710132 Share on other sites More sharing options...
DarkWater Posted December 9, 2008 Share Posted December 9, 2008 @CV: That's why he included the document path... I'd suggest checking out realpath() to fix up those ../'s and stuff. Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710146 Share on other sites More sharing options...
.josh Posted December 9, 2008 Share Posted December 9, 2008 Well I was mostly just explaining to him what ../ meant so as to give him an idea of how to find the correct path. If /Library/WebServer/Documents/ is the document root, and you're saying that your orders directory is just 'outside' of that, do you mean to say that this /Library/WebServer/orders/orders.txt is the path to the fie? Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710150 Share on other sites More sharing options...
neridaj Posted December 9, 2008 Author Share Posted December 9, 2008 I know that ../ gets me out of the dir. In this example script the full path based on the OSX install of Apache is "/Library/WebServer/Documents/" - where the script is being run from. So, does "/Library/WebServer/Documents/../orders/orders.txt" point to a file located between "/Library/WebServer/Documents/" and "orders/" i.e., a file sitting in "/Library/WebServer/Documents/"? In any case it doesn't seem to matter where I'm trying to fopen() from, if I use "orders/orders.txt" or even "orders.txt" as the file path param, it always returns false. Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710722 Share on other sites More sharing options...
.josh Posted December 9, 2008 Share Posted December 9, 2008 If the full path of your file is for instance /Library/WebServer/Documents/foo/bar/orders/orders.txt and you do /Library/WebServer/Documents/../orders/orders.txt that's the same as saying /Library/WebServer/Documents/bar/orders/orders.txt which will result in a 404 error or false or whatever, depending on how you're trying to access it. Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-710765 Share on other sites More sharing options...
neridaj Posted December 10, 2008 Author Share Posted December 10, 2008 The file path is directly from a PHP book and I believe the path was setup this way to prevent problems when moving to a different server. In any case, fopen() returns false no matter what file path is given. Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-711612 Share on other sites More sharing options...
Andy-H Posted December 10, 2008 Share Posted December 10, 2008 orders.txt is chmodded to 666? Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-711614 Share on other sites More sharing options...
neridaj Posted December 10, 2008 Author Share Posted December 10, 2008 It turns out that I needed to chmod the dir, thanks man. Link to comment https://forums.phpfreaks.com/topic/136144-fopen-problems/#findComment-711725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.