如何在 perl 中使用 <a href> 向文件提供 link?

How to provide link to a file using <a href> in perl?

我有一个 Perl CGI 脚本,它调用 HTML 表单,接受输入并处理它。

我想将生成的文件上传到同一个本地主机服务器 (apache2),但在处理后,它生成了生成的文件并停止而不显示任何内容。生成的文件位于 cgi-bin 文件夹中的临时文件夹($dir)中。

我尝试使用 <a href> HTML 标签,但它不起作用。

print "Content-Type: text/html";        
print '<a href="http://localhost/cgi-bin/$dir/test.txt" target="_top">Download your file</a>';

有没有其他方法可以在 Perl 中使用 <a href> 标签?

The resultant file is in a temporary folder ($dir) located in cgi-bin folder

不要那样做。

cgi-bin 应仅包含 CGI 程序。

您的服务器几乎肯定已配置,因此它将尝试以 CGI 程序的形式执行 任何东西

您的包含数据的文本文件不是程序,尝试将其视为程序会导致错误。

将文件保存在外部 cgi-bin 的某处(或者根本不保存,直接从 CGI 程序输出到浏览器)。