In addition, your code example is inherently flawed:
$file = fopen("http://servername/directory/type4.txt", "w");
fputs($file,"test");
fclose($file);
although PHP is safe enough to test the file handle internally instead of just trying to dereference a NULL pointer like C or C++ would!
Since fopen() is not guaranteed to succeed, you really should be saying:
if ($file = fopen("http://servername/directory/type4.txt", "w"))
{
fputs(...);
fclose(...);
}
else
{
echo "Oops, can't do it";
// or whatever other error logging/recovery you
// might prefer over PHP's default response, which
// is to just barf the error message directly to
// the output.
}
In many cases, I have my code email me a complaint when something like this goes wrong, in addition to issuing some kind of gentle apology to the user of the site.