我正在尝试编写将导出二进制文件的shell脚本。
以下是HTML部分,
<form name="submitForm" action="./exportfile.cgi" method="post" enctype="multipart/form-data">
<input type="submit" id="btnExport" value="Export/>
</form>
以下是CGI部分,它只是一个草案,提供了有关我想要实现的内容的更多信息
#!/bin/sh
#push some file to IE so it will pop-up a file Save-as pop-up.
echo "Content-type: application/octet-stream"
echo "Content-Length: $contentLength"
echo "Content-Transfer-Encoding: binary"
echo "Content-Disposition: attachment; filename=$filename"
echo ""
echo "$fileContent"
有什么办法可以实现上述目标吗?任何图书馆?有没有文章参考?
感谢您的指导。
答案 0 :(得分:2)
我使用下面的脚本
#!/bin/sh
filename="binaryfile.bin"
contentLength=$(wc -c < binaryfile.bin)
echo "Content-type: application/octet-stream"
echo "Content-Length: $contentLength"
echo "Content-Transfer-Encoding: binary"
echo "Content-Disposition: attachment; filename=$filename"
echo ""
cat binaryfile.bin