I have two php functions that are called upon consecutive requestes:
This is called on the first request:
public static function ProcessResponseFile($request_file_content)
{
session_start();
$temp_file = tempnam("./tmp", "file");
file_put_contents($temp_file, $request_file_content);
$_SESSION['request_response'] = $temp_file;
return file_get_contents($temp_file);
}
The following function is called on the second request:
public static function GetResponseFileContent()
{
session_start();
$filename = $_SESSION['request_response'];
$handle = fopen($filename, "r");
$response_content = fread($handle, filesize($filename));
fclose($handle);
// $response_content = file_get_contents($_SESSION['request_response']);
unlink($_SESSION['request_response']);
unset($_SESSION['request_response']);
return $response_content;
}
The $response_content
is empty. If I comment the unlink and unset, I get the appropriate file contents.
Why is that ?
I want to download the returned value of GetResponseFileContent()
if (isset($_POST['submit_download'])) {
ob_end_clean();
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=raspuns.xml");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
session_start();
echo Application::GetResponseFileContent();
}