Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error on creating file

Status
Not open for further replies.

carlosparedes

Programmer
Jun 10, 2007
12
GB
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>
 
make sure that the relevant permissions are set to allow the server process to have write access on the directory in question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top