Probably a permissions problem. As most web servers run PHP scripts under a separate user account rather than under each user's personal account, you may need to add "world" write permission to the directory where you want to write this file. A quick test would be:
<?php
$ft = fopen($_SERVER['DOCUMENT_ROOT'].'/'.$thefilename,'w');
if($ft == FALSE)
{
if(!is_writable($_SERVER['DOCUMENT_ROOT']))
{
die("You need to add write permission to ".$_SERVER['DOCUMENT_ROOT']);
}
elseif(file_exists($_SERVER['DOCUMENT_ROOT'].'/'.$thefilename) && !is_writable($_SERVER['DOCUMENT_ROOT'].'/'.$thefilename)
{
die($_SERVER['DOCUMENT_ROOT'].'/'.$thefilename." already exists but is not writable by this script");
}
else
{
die("An unknown error occurred trying to open ".$_SERVER['DOCUMENT_ROOT'].'/'.$thefilename." for writing");
}
}
?>
Also, while trying to debug PHP script problems, you might want to remove the error-suppression "@" characters from you function calls until you are sure the script is correct.