carlosparedes
Programmer
hi guys
I have the code below to create and write to a file. I can not figure out what's wrong, because I am getting the error "unable to create file".
Can anyone help me please
Thanks in advance
sandra
<Code>
//if there are no errors, save the details to the date/time stamped file
if(!$errorlevel) {
//create a unique_filename;
$index=0;
$filepart=sprintf('%svisireg%04d%02d%02d%02d%02d%02d',$filepath,$now['year'],$now['mon'],$now['mday'],$now['hours'],$now['minutes'],$now['seconds']);
do {
$index++;
$filename=sprintf('%s%03d.vrd',$filepart,$index);
} while (file_exists($filename));
//create the file
if(!$filehandle=fopen($filename,'wb')) //{
// die('<font colour="#FF0000">Unable to create file "' . $filename . '"</font>');
}
fwrite($filehandle,"[Main]\r\n");
fwrite($filehandle,sprintf("Title=%s\r\n",$titles[$title]));
fwrite($filehandle,sprintf("Firstname=%s\r\n",$FirstName));
fwrite($filehandle,sprintf("Surname=%s\r\n",$Surname));
fwrite($filehandle,sprintf("Company=%s\r\n",$Company));
fwrite($filehandle,sprintf("CarReg=%s\r\n",$CarReg));
fwrite($filehandle,"[Details]\r\n");
fwrite($filehandle,sprintf("ExpectedDate=%04d%02d%02d\r\n",$year,$month,$date));
fwrite($filehandle,sprintf("AlwaysExpected=%s\r\n",$Always));
fwrite($filehandle,"[Host]\r\n");
fwrite($filehandle,sprintf("Firstname=%s\r\n",$HostFirstName));
fwrite($filehandle,sprintf("Surname=%s\r\n",$HostSurname));
fwrite($filehandle,sprintf("Department=%s\r\n",$HostDepartment));
fwrite($filehandle,sprintf("Location=%s\r\n",$HostLocation));
fwrite($filehandle,sprintf("PhoneNumber=%s\r\n",$HostPhoneNumber));
fclose($filehandle);
$page=1;
}
} else {
//set up defaults
$FirstName=$Surname=$Company=$CarReg='';
$HostFirstName=$HostSurname=$HostDepartment=$HostLocation=$HostPhoneNumber='';
$title=0;
$month=$now['mon'];
$year=$now['year'];
$date=$now['mday'];
$Always=0;
}
?>
</Code>
I have the code below to create and write to a file. I can not figure out what's wrong, because I am getting the error "unable to create file".
Can anyone help me please
Thanks in advance
sandra
<Code>
//if there are no errors, save the details to the date/time stamped file
if(!$errorlevel) {
//create a unique_filename;
$index=0;
$filepart=sprintf('%svisireg%04d%02d%02d%02d%02d%02d',$filepath,$now['year'],$now['mon'],$now['mday'],$now['hours'],$now['minutes'],$now['seconds']);
do {
$index++;
$filename=sprintf('%s%03d.vrd',$filepart,$index);
} while (file_exists($filename));
//create the file
if(!$filehandle=fopen($filename,'wb')) //{
// die('<font colour="#FF0000">Unable to create file "' . $filename . '"</font>');
}
fwrite($filehandle,"[Main]\r\n");
fwrite($filehandle,sprintf("Title=%s\r\n",$titles[$title]));
fwrite($filehandle,sprintf("Firstname=%s\r\n",$FirstName));
fwrite($filehandle,sprintf("Surname=%s\r\n",$Surname));
fwrite($filehandle,sprintf("Company=%s\r\n",$Company));
fwrite($filehandle,sprintf("CarReg=%s\r\n",$CarReg));
fwrite($filehandle,"[Details]\r\n");
fwrite($filehandle,sprintf("ExpectedDate=%04d%02d%02d\r\n",$year,$month,$date));
fwrite($filehandle,sprintf("AlwaysExpected=%s\r\n",$Always));
fwrite($filehandle,"[Host]\r\n");
fwrite($filehandle,sprintf("Firstname=%s\r\n",$HostFirstName));
fwrite($filehandle,sprintf("Surname=%s\r\n",$HostSurname));
fwrite($filehandle,sprintf("Department=%s\r\n",$HostDepartment));
fwrite($filehandle,sprintf("Location=%s\r\n",$HostLocation));
fwrite($filehandle,sprintf("PhoneNumber=%s\r\n",$HostPhoneNumber));
fclose($filehandle);
$page=1;
}
} else {
//set up defaults
$FirstName=$Surname=$Company=$CarReg='';
$HostFirstName=$HostSurname=$HostDepartment=$HostLocation=$HostPhoneNumber='';
$title=0;
$month=$now['mon'];
$year=$now['year'];
$date=$now['mday'];
$Always=0;
}
?>
</Code>