在客户端上复制文件';s机器的网页


Make a copy of file on client's machine from web page

我是一名PHP开发人员。我正在处理一个项目,其中用户有一个表单。用户在字段中提交数据。在此表单中,用户选择一个图像文件。

现在,当用户点击提交按钮时,我想在用户本地机器的某个特定位置复制所选图像。

我不知道如何做到这一点。有人能指导我吗?

提前感谢

您可以触发下载,下载将由浏览器默认值和用户操作处理,在大多数情况下会下载到users downloads文件夹。

$file = 'path-to-file/your-file-name.png';
$quoted = sprintf('"%s"', addcslashes(basename($file), '"'''));
$size   = filesize($file);
header('Content-Type: image/png');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$quoted); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.$size);