[英]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);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.