我試圖生成一個.html文件並將其下載。創建文件並下載它php
我的問題:首先我檢查文件是否存在,如果爲真我刪除它並創建一個新的。
當我點擊生成文件時,下載的文件始終是第一個創建的文件,並沒有更新。我檢查了文件manualy和它的好,但下載是舊的。如果我刪除服務器上的文件,我可以下載。
檢查部位:bit.ly/1crrcif
$content = "<html></head></head><body>All content here</body></html>";
if(empty($error)){
echo "<h3>File generated</h3>";
$my_file = 'change_nameto_index.html';
if (file_exists($my_file)) {
echo "file exists";
unlink($my_file);
}
$new_file = 'change_nameto_index.html';
$handle = fopen($new_file, 'w') or die('Cannot open file: '.$new_file);
$data = $content;
fwrite($handle, $data);
fclose($handle);
echo "<a download='change_nameto_index.html' href='change_nameto_index.html'>"
. "<b class='download'>Download</b></a>"
;
沒有關閉:如果(空($錯誤)){ – SteAp