Perl CGI通过Web浏览器下载文件
发布时间:2020-12-15 22:05:17 所属栏目:大数据 来源:网络整理
导读:需要一些可以从服务器机器下载文件的cgi-perl脚本. EX:点击下载链接,它将打开“另存为” 窗口,将允许我将文件保存在我的本地计算机上. 我使用CGI创建了一个网页,使用这个我将上传文件到服务器并运行perl脚本将其转换为其他格式(直到这里我完成了).现在我需
需要一些可以从服务器机器下载文件的cgi-perl脚本. EX:点击下载链接,它将打开“另存为”
窗口,将允许我将文件保存在我的本地计算机上. 我使用CGI创建了一个网页,使用这个我将上传文件到服务器并运行perl脚本将其转换为其他格式(直到这里我完成了).现在我需要将此文件恢复(下载回)到系统. #!/usr/bin/perl #print "Content-type: text/htmlnn"; my $filepath='/upload/testing.pm'; print "Content-Type: text/htmlnn"; open("DOWNLOADFILE","<".$filePath); while($fileContents = <DOWNLOADFILE>) { print $fileContents; } print "Content-Type: textn"; print "Content-Disposition: attachment; filename='testing.pm'n"; print "Content-Description: File to downloadnn"; close DOWNLOADFILE; 将文件从我的机器(客户端)上传到服务器机器,在那里我有一个perl脚本,它将文件转换为另一种格式,并将新转换的文件保存到dir ex:/ upload->直到这里我完成了脚本编写. 现在我需要使用浏览器将此文件下载回客户端计算机.在这种情况下,我试图将testing.pm文件下载回客户端计算机. 解决方法
重新排列HTML标头有效.
这是工作脚本.一个人可以照原样使用它 use CGI; my $html= new CGI; #get the file name from URL ex. http://<server_IP>/cgi-bin/download.cgi?a=testing.txt my $file= $html->param('a'); # $file is nothing but testing.txt my $filepath= "/var/www/upload/$file"; print ("Content-Type:application/x-downloadn"); print "Content-Disposition: attachment; filename=$filenn"; open FILE,"< $filepath" or die "can't open : $!"; binmode FILE; local $/ = 10240; while (<FILE>){ print $_; } close FILE; # use Unlink if u want to delete the files after download. #unlink ($filepath); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |