0
votes

I have a link on my page that goes to "basedir/Controls/ProcessExcel.php"

ProcessExcel.php generate an .xls file named Rapport.xls in basedir. So the path is basedir/Rapport.xsl.

The problem is that when I am redirect to ProcessExcel.php after it is finish generating Rapport.xlsI can't get Rapport.xls to dowload from server.

Here is the code for ProcessExcel.php

if($cn-­­>DBConnexion())
{
    //Format stuff here, do stuff there... 
    //This is Validation on my SQLDATA, etc...
}
//Create the .xls file
$writer = new PHPExcel_Writer_Excel5($phpe);
//Save the .xls file
$writer->save("../Rapport.xls");

$fullPath = '../Rapport.xls';

if (file_exists($fullPath)) {       
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header('Content-Disposition: attachment;filename="Rapport.xls"'); 
header("Content-Transfer-Encoding: binary ");

    readfile($fullPath);
    exit();
}

It gives me the error code 500 :

The website encountered an error while retrieving http://CantPOSTRealURLSorry.com/basedir/Controls/ProcessExcel.php. It may be down for or configured incorrectly.

EDIT: Error in log says:

PHP Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open ../Rapport.xls. It may be in use or protected.' in C:\basedir\Classes\PHPExcel\Shared\OLE\PPS\Root.php:93 Stack trace: 0 C:\inetpub\wwwroot\solutions_spb\Classes\PHPExcel\Writer\Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('../Rapport.xls') 1 C:\inetpub\wwwroot\solutions_spb\Controls\ProcessExcel.php(224): PHPExcel_Writer_Excel5->save('../Rapport.xls') 2 {main} thrown in C:basedir\Classes\PHPExcel\Shared\OLE\PPS\Root.php on line 93

EDIT 2: I have basicly the same error when trying to send an email with another script. I think both issue might be related.

1
check your logs for the real error, maybe a permission issueDevZer0
It is a permission issues its said : PHP Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open ../Rapport.xls. It may be in use or protected.' in C:\basedir\Classes\PHPExcel\Shared\OLE\PPS\Root.php:93 Stack trace: #0 C:\inetpub\wwwroot\solutions_spb\Classes\PHPExcel\Writer\Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('../Rapport.xls') #1 C:\inetpub\wwwroot\solutions_spb\Controls\ProcessExcel.php(224): PHPExcel_Writer_Excel5->save('../Rapport.xls') #2 {main} thrown in C:\basedir\Classes\PHPExcel\Shared\OLE\PPS\Root.php on line 93Sebastien
@DevZer0 could you please post your previous comment as an answer? I would choose it.Sebastien
thanks for that, i did what you saidDevZer0

1 Answers

1
votes

You can always check your logs for the real error, maybe a permission issue