douruhu4282 2011-06-25 11:44
浏览 49
已采纳

如何下载带位置选择选项的文件

I am downloading file from server to local computer like this:

$file = ( "TestFile.txt" );     
header( "Content-Type: application/octet-stream" );
header( "Accept-Ranges: bytes" );
header( "Content-Length: " . filesize( $file ) );
header( "Content-Disposition: attachment; filename=testfile.txt" );
readfile( $file );

It is working but it always save file in download folder without asking location. I want to open window like saving any document in OpenOffice/MS Word with option to choose any location on file system and create new folder option. My desired window also opears when we save as in browser window.

Hope you understand my problem. Is it possible to do this which work in all browsers/OS.

Thanks

  • 写回答

3条回答 默认 最新

  • donglvmang8638 2011-06-25 12:11
    关注

    The specification of Content-Disposition reads that the receiving user agent should ignore any path component in filename parameter value:

    The receiving [user agent] 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.

    The reason for this is that it prones a security vulnerability:

    Since this memo provides a way for the sender to suggest a filename, a receiving [user agent] must take care that the sender's suggested filename does not represent a hazard. Using UNIX as an example, some hazards would be:

    • Creating startup files (e.g., ".login").
    • Creating or overwriting system files (e.g., "/etc/passwd").
    • Overwriting any existing file.
    • Placing executable files into any command search path (e.g., "~/bin/more").
    • Sending the file to a pipe (e.g., "| sh").
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料