eMonk Posted October 28, 2008 Share Posted October 28, 2008 i'm getting the error in the topic with this code. i don't think i'm pointing to the correct path using $DOCUMENT_ROOT. $DOCUMENT_ROOT = $SERVER['DOCUMENT ROOT']; // open file for appending @ $fp = fopen("$DOCUMENT_ROOT/www.domain.com/orders/orders.txt", 'ab'); flock($fp, LOCK_EX); if (!$fp) { echo "<p><strong>Your order could not be processed at this time. Please try again later.</strong></p></body></html>"; exit; } - the .php file is uploaded in /www.domain.com/test/processorder.php - the orders.txt is uploaded in /www.domain.com/orders/orders.txt how do i know 100% if i'm pointing to the right file in fopen? Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
ratcateme Posted October 28, 2008 Share Posted October 28, 2008 by /www.domain.com/orders/orders.txt do you mean the complete file system root? then you don't need the document root thing. also try adding if($fp){ echo "Failed to open file"; exit; } before the flock statement. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676353 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 here's my html output Warning: flock() expects parameter 1 to be resource, boolean given in /usr/www/virtual/emonk/www.domain.com/test/processorder.php on line 68 Your order could not be processed at this time. Please try again later. line 68 flock($fp, LOCK_EX); your if statement was also added to the php file but doesn't appear in the html output... Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676359 Share on other sites More sharing options...
ratcateme Posted October 28, 2008 Share Posted October 28, 2008 i think it should be $DOCUMENT_ROOT/orders/orders.txt check what document_root is set to using the phpinfo(); (put <?php phpinfo(); ?> all on one page by itself). then you should be able to tell. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676360 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 by /www.domain.com/orders/orders.txt do you mean the complete file system root? then you don't need the document root thing. i tried using @ $fp = fopen("http://www.domain.com/orders/orders.txt", 'ab'); & @ $fp = fopen("$DOCUMENT_ROOT/orders/orders.txt", 'ab'); but get the same error. Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676361 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 phpinfo() _SERVER["DOCUMENT_ROOT"] /www/virtual/emonk/www.domain.com Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676363 Share on other sites More sharing options...
ratcateme Posted October 28, 2008 Share Posted October 28, 2008 you want it to be @ $fp = fopen("$DOCUMENT_ROOT/orders/orders.txt", 'ab'); Scott. Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676364 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 i'm still getting the same error with @ $fp = fopen("$DOCUMENT_ROOT/orders/orders.txt", 'ab'); Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676365 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 i found one typo... $DOCUMENT_ROOT = $SERVER['DOCUMENT ROOT']; should be $DOCUMENT_ROOT = $SERVER['DOCUMENT_ROOT']; (missing "_" in $SERVER['DOCUMENT ROOT']) but still getting the same error.... Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676366 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 actually.. it SHOULD BE $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; and now i'm getting your echo... Failed to open file Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676367 Share on other sites More sharing options...
eMonk Posted October 28, 2008 Author Share Posted October 28, 2008 i removed your if statement and now its WORKING! Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676368 Share on other sites More sharing options...
ratcateme Posted October 28, 2008 Share Posted October 28, 2008 sorry should have had a ! in it. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-676376 Share on other sites More sharing options...
eenriqu Posted October 9, 2009 Share Posted October 9, 2009 Hi there, I'm getting the above error message. I'm not sure what's wrong becaus I beleive I'm pointing to the correct path. I'm using the example for the PHP and MySQL Web Development book whick I think is the same example used by eMonk in a previous topic. // open file for appending @ $fp = fopen("http://137.15.xxx.xxx/officet/Commitees/Auto/orders.txt", "a"); flock($fp, 2); . When adding retcateme (Scott's) suggestion before the flock statement, I get the "Failed to Open" message if($fp){ echo "Failed to open file"; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-933702 Share on other sites More sharing options...
usmc.betancourt Posted August 13, 2012 Share Posted August 13, 2012 step 1To solve the problem find the line that says: @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); Step 2 change it from this @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); to this @ $fp = fopen("$DOCUMENT_ROOT/orders/orders.txt", 'ab'); step 3save your php file step 4Also create a file in your server with the name orders and inside create a text file named orders.txt Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-1369134 Share on other sites More sharing options...
Christian F. Posted August 13, 2012 Share Posted August 13, 2012 This thread is almost 3 years old, usmc.betancourt. Please check the date of the thread before replying to it, so that you avoid thread-necroing in the future. Quote Link to comment https://forums.phpfreaks.com/topic/130391-solved-warning-flock-expects-parameter-1-to-be-resource/#findComment-1369170 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.