PHP error- expects parameter 1 to be resource, boolean given

Resources are a type within PHP, this includes for example a string, integer or objects. Often this message is related to the obsolete function mysql_ which you can replace with mysqli on PDO.
The error is also often a result of a value that returns false. In that case there is an additional error handler to further check this.
Use the function var_dump to check as much as possible where exactly it goes wrong.

if(!$fp){   trigger_error('Failed to allocate resource');
exit;
}

These error messages can then be handled in the code and the write permissions for these files can be checked.