Jump to content

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


Maracles

Recommended Posts

Hi, there is already a similar thread on this forums at at the following link however the solution here did not work for me:

 

http://www.phpfreaks.com/forums/index.php?topic=223119.0

 

I was getting same error code as above until I finally found a spelling mistake and now I get the 'Your order could not be processed at this time. Please try again later.' which means that there is an error somewhere but I don't know how to tell what exactly it is or fix it.

 

The book I'm learning from (PHP and MySQL Web Development - L. Welling)  hints it may be a permissions thing but offers no recommendations for fixing it.

 

My code is below:

 

// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/../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;
}

fwrite ($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);

echo "<p>Order written.</p>";

 

Any help is much appreciated

 

 

 

Set the error level and reporting, then remove the @ from

@ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab');

The @ suppresses any errors, so if your file cannot be opened, the first you know about it is when the flock() gives you this error. Fix the problem in the fopen()

 

I added that to my script and ran it again. I got the following error below. I then created the directory on my server itself and ran the script again and it worked. Does this mean that there are insufficient permissions for the script to create directory itself? If so how can I change this?

 

Thank you for your help, was stuck on this for quite a while!!

 

 

Notice: Undefined variable: date in /homepages/36/d271495301/htdocs/Websites/ChimEnt/phpdev/chap1/processorder.php on line 109

 

Warning: fopen(/kunden/homepages/36/d271495301/htdocs/Websites/ChimEnt/../orders/orders.txt) [function.fopen]: failed to open stream: No such file or directory in /homepages/36/d271495301/htdocs/Websites/ChimEnt/phpdev/chap1/processorder.php on line 115

 

Warning: flock(): supplied argument is not a valid stream resource in /homepages/36/d271495301/htdocs/Websites/ChimEnt/phpdev/chap1/processorder.php on line 118

Your order could not be processed at this time. Please try again later.

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.