我遇到了麻烦,因为我无法将下载的文件保存到文件夹中。以下代码仅能下载文件。代码应该如何保存?
file_put_contents($file, $data_row, LOCK_EX);
file_put_contents('/var/www/file', $file);
download($file);
function download($file) {
if (!headers_sent()) {
if (file_exists($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
if (ob_get_level()) {
ob_end_clean();
}
readfile($file, 'rb');
exit();
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
}
谢谢。