Jump to content

[SOLVED] Warning: flock() expects parameter 1 to be resource


eMonk

Recommended Posts

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?

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.

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...

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.

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.

  • 11 months later...

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;
}

  • 2 years later...

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.