DocumentRoot以外の場所にあるファイルをダウンロードさせようとして、プログラム側で「Location」させても、普通はアクセスできない。
そういった場合は前記事(http://www.igreks.jp/dev/2009/10/perlmysql2.html)の応用で、「cat」コマンドを利用するとダウンロードできるようになる。
-----------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
my $dir = '../../hoge'; #Documentroot外のディレクトリ
my $file = 'huga'; #その中にあるファイル
print "Content-Type: application/octet-stream\n";
print "Content-Type: application/download; name=$file\n";
print "Content-Disposition: attachment; filename=$file\n";
print "\n";
#### print content
system "cat $dir/$file";
exit;
-----------------------------------------------------------------------
※DocumentRoot以下に置いてBasic認証かけるよりは安全?
※LWP転送するときもOK
そういった場合は前記事(http://www.igreks.jp/dev/2009/10/perlmysql2.html)の応用で、「cat」コマンドを利用するとダウンロードできるようになる。
-----------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
my $dir = '../../hoge'; #Documentroot外のディレクトリ
my $file = 'huga'; #その中にあるファイル
print "Content-Type: application/octet-stream\n";
print "Content-Type: application/download; name=$file\n";
print "Content-Disposition: attachment; filename=$file\n";
print "\n";
#### print content
system "cat $dir/$file";
exit;
-----------------------------------------------------------------------
※DocumentRoot以下に置いてBasic認証かけるよりは安全?
※LWP転送するときもOK

コメントする