0
我有指一經連續requestes叫了兩個PHP函數:返回文件的內容刪除,因爲新的文件下載後
這就是所謂的第一個請求:
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);
}
下面的函數調用上第二個請求:
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;
}
$response_content
爲空。如果我評論取消鏈接並取消設置,我會得到相應的文件內容。 這是爲什麼?
我想下載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();
}
如果您只是評論其中一行,但不是兩者都有? – Barmar
同樣的事情發生在這兩行的評論的任何組合,但我仍然想要做它們,清除會話變量並刪除文件。 – AlexandruC
我只是想弄清楚什麼是依賴,而不是暗示它是一個修復。我不明白他們中的任何一個如何能夠對他們之前分配的變量產生影響。如果你在'unlink/unset'之前和之後回顯變量會發生什麼? – Barmar