cgidecode unpacks url-encoded or multipart-encoded data into files.
cgidecode -e multipart -D mydir -C .cdisp myfile <form-data echo Upload filename is: `cat mydir/myfile.cdisp/filename` echo Upload filetype is: `cat mydir/myfile.cdisp/content-type` echo Upload filesize is: `du -s mydir/myfile`
Simple CGI Example
#!/bin/sh export TMPDIR=/tmp/$$memo$UNIQUE_ID trap "rm -rf $TMPDIR" 0 1 2 15 echo "Content-type: text/html"; echo "" test "POST" = "$REQUEST_METHOD" && cgidecode -q -D $TMPDIR memo cp $TMPDIR/memo /var/www/memo 2>/dev/null echo '<html><body>' echo '<form action='`basename $0`' enctype="multipart/form-data" method=post>' echo "<textarea name=memo>`cat /var/www/memo 2>/dev/null`</textarea>" echo '<input type=submit><input type=reset></form>' echo '</body></html>'
A shell script makes a good simple CGI language, given a way to convert url-encoded or multipart-encoded data into a format that is easy for a shell script to manipulate. cgidecode converts url-encoded or mime-encoded variables into files, where the filename is the name of the variable and the file content is the value of the variable.
Copyright University of Toronto 2007, 2008, 2010, 2015, 2016. Written by John DiMarco
Permission is granted to anyone to use this software for any purpose on any computer system, and to alter it and redistribute it freely, subject to the following restrictions:
The author and the University of Toronto are not responsible for the consequences of use of this software, no matter how awful, even if they arise from flaws in it.
The origin of this software must not be misrepresented, either by explicit claim or by omission. Since few users ever read sources, credits must appear in the documentation.
Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. Since few users ever read sources, credits must appear in the documentation.
This notice may not be removed or altered.