How change the default download location in PHP

本秂侑毒 提交于 2021-02-05 09:24:25

问题


my code:

$zip_name="download.zip";
$ctype="application/zip";

// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");

// change, added quotes to allow spaces in filenames

header("Content-Disposition: attachment; filename=\"".basename($zip_name)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($zip_name));
readfile("$zip_name");

now files download on Downloads folder.

i need download all files in D: drive.


回答1:


This is not possible. A webserver cannot tell a client where to save a file. Imagine the security implications if a site could specify an exact location for a file save operation.

See RFC 2183, section 2.3:

The receiving MUA SHOULD NOT respect any directory path information
that may seem to be present in the filename parameter
. The filename
should be treated as a terminal component only. Portable
specification of directory paths might possibly be done in the future via a separate Content-Disposition parameter, but no provision is
made for it in this draft.



来源:https://stackoverflow.com/questions/11917477/how-change-the-default-download-location-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!