I'm currently using an isset to get the username of the user logged in to save the Excel document to there area in my site directory. Now I am also using a second isset for an encryption so the user cannot simply change the username isset and save there files to someone else's directory unless they know their encryption key as well which changes daily, or on press. Now when I try I get an error message, now i'm not sure if it's the isset not working with it or if it's the documents source files to create the document. Anyone have any ideas on how to fix this?
Error
Warning: fopen(USERS/".$Username."/Documents/DocName.xls) [function.fopen]: failed to open stream: No such file or directory in public_html/Site/PHP/PHPExcel/Shared/OLE/PPS/Root.php on line 90
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open USERS/".$Username."/Documents/DocName.xls. It may be in use or protected.' in /public_html/Site/PHP/PHPExcel/Shared/OLE/PPS/Root.php:93 Stack trace: 0 /public_html/Site/PHP/PHPExcel/Writer/Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('USERS/".$Userna...') #1 /public_html/Site/Create.php(124): PHPExcel_Writer_Excel5->save('USERS/".$Userna...') #2 {main} thrown in /public_html/SitePHP/PHPExcel/Shared/OLE/PPS/Root.php on line 93
PHP
<?php
if (isset($_GET['logout'])){
session_destroy();
header("Location: index.php");
exit();
}
else{
if (isset($_GET['Username'])){
if (isset($_GET['Encryption'])){
$Username = $_GET['Username'];
$Encryption = $_GET['Encryption'];
if (is_dir("USERS/".$Username) === true) {
if($Encryption == file_get_contents("USERS/".$Username."/Encryption.txt")){
$NoOfDocs = file_get_contents("USERS/".$Username."/NoOfDocuments.txt");
}
else{
header("Location: 201Error.php");exit();
}
}
else{
header("Location: 201Error.php");exit();
}
}
}
}
//Excel Transfer
$myFile=fopen("USERS/".$Username."/RiskAssessment/A1.txt","r") or exit("Can't open file!");
$A1 = fgets($myFile);
if ($Spo === false) $A1 = '';
fclose($myFile);
$myFile=fopen("USERS/".$Username."/RiskAssessment/A2.txt","r") or exit("Can't open file!");
$A2 = fgets($myFile);
if ($Spo === false) $A2 = '';
fclose($myFile);
$myFile=fopen("USERS/".$Username."/RiskAssessment/A3.txt","r") or exit("Can't open file!");
$A3 = fgets($myFile);
if ($Spo === false) $A3 = '';
fclose($myFile);
$myFile=fopen("USERS/".$Username."/RiskAssessment/A4.txt","r") or exit("Can't open file!");
$A4 = fgets($myFile);
if ($Spo === false) $A4 = '';
fclose($myFile);
$myFile=fopen("USERS/".$Username."/RiskAssessment/A5.txt","r") or exit("Can't open file!");
$A5 = fgets($myFile);
if ($Spo === false) $A5 = '';
fclose($myFile);
$Date = date("d/m/Y");
Include_once 'PHP/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$activeSheet = $objPHPExcel->getActiveSheet();
$objPHPExcel->getActiveSheet()->setTitle('Risk Assessment');
$border = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
//Set Up
$activeSheet->setCellValue('A1','Risk Assessment');
$activeSheet->setCellValue('F1',$Date);
$objPHPExcel->getActiveSheet()->mergeCells('A1:E1');
$objPHPExcel->getActiveSheet()->mergeCells('F1:I1');
//Title
$title = array(
'font' => array(
'bold' => true,
'size' => 32,
));
$horizontalCenter = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
)
);
$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($title);
//Basic Information
$objPHPExcel->getActiveSheet()->mergeCells('B2:D2');
$objPHPExcel->getActiveSheet()->mergeCells('A3:I3');
$objPHPExcel->getActiveSheet()->mergeCells('A4:I4');
$objPHPExcel->getActiveSheet()->mergeCells('A5:I5');
$objPHPExcel->getActiveSheet()->mergeCells('A6:I6');
$objPHPExcel->getActiveSheet()->mergeCells('A7:I7');
$objPHPExcel->getActiveSheet()->mergeCells('A8:I8');
$objPHPExcel->getActiveSheet()->mergeCells('A9:I9');
$objPHPExcel->getActiveSheet()->mergeCells('A10:I10');
$objPHPExcel->getActiveSheet()->mergeCells('F11:G11');
$objPHPExcel->getActiveSheet()->mergeCells('H11:I111');
$objPHPExcel->getActiveSheet()->mergeCells('F12:G12');
$objPHPExcel->getActiveSheet()->mergeCells('H13:I13');
$activeSheet->setCellValue('B2','Risk No.1');
$activeSheet->setCellValue('A3','What are the hazards?');
$activeSheet->setCellValue('A4', $A1);
$activeSheet->setCellValue('A5','What are you already doing?');
$activeSheet->setCellValue('A6',$A2);
$activeSheet->setCellValue('A7','Do you need to do anything else to control this risk?');
$activeSheet->setCellValue('A8',$A3);
$activeSheet->setCellValue('A9','Action by who?');
$activeSheet->setCellValue('A10',$A4);
$activeSheet->setCellValue('F11','Action by when?');
$activeSheet->setCellValue('F12',$A5);
$activeSheet->setCellValue('H11','Done');
$activeSheet->setCellValue('H12',$A6);
//Document Settings
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('USERS/".$Username."/RiskAssessment/Risk_Assessment.xls');
?>