簡體   English   中英

使用內容處置將文件保存在某些特定位置

[英]Save file in some specific location using content disposition

下面的代碼可以完美地下載當前PHP網頁的.html文件

$filename = 'filename.html';
header('Content-disposition: inline; filename=' . $filename);
header('Content-type: text/html');

有什么方法可以將文件保存在某些特定位置,而不是下載響應。

例如:如果我想將此filename.html文件保存在/export/www/html/myproject/var/htmlpages

還嘗試了以下邏輯作為替代:

ob_start();
file_put_contents('myfile.html', ob_get_contents());

但是它生成空文件

使用fopen()在特定目錄中寫入文件,而不是像這樣的下載響應:

<?php
$fp = fopen('data.txt', 'w');    // here you can pass the directory path + filename
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);
?>

fwrite()文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM