سؤال

I am trying to write shell script which will export binary file.

Below is the HTML part,

<form name="submitForm" action="./exportfile.cgi" method="post" enctype="multipart/form-data">
    <input type="submit" id="btnExport" value="Export/>
</form>

Below is the CGI part, It is just a draft to give more information about what I am trying to achieve

#!/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"

Is there any way I can achieve the above? Any library? Any article reference?

Appreciate your guidance.

هل كانت مفيدة؟

المحلول

I got it working with the below script,

#!/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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top