slitaz-arm view cgi-adm/plugins/upload/upload.cgi @ rev 96

cgi-adm: add upload plugin
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 13 00:56:19 2014 +0200 (2014-04-13)
parents
children 2fee3c2b3980
line source
1 #!/bin/sh
2 #
3 # TazBerry CGI Plugin - File upload
4 #
6 case " $(POST) " in
7 *\ upload\ *)
8 [ "$updir" ] || updir="/var/cache/uploads"
9 [ -d "$updir" ] || mkdir -p ${updir}
10 upload="true"
11 name=$(FILE file name)
12 tmpname=$(FILE file tmpname)
13 # Move/Overwrite files to the cloud and set permissions
14 if ! mv -f ${tmpname} ${updir}/${name}; then
15 echo "ERROR: ${name}" && exit 1
16 fi
17 chmod a+r ${updir}/${name}
18 rm -rf /tmp/httpd_post* ;;
19 esac
21 if [ "$(GET upload)" ] || [ "$upload" ]; then
22 [ "$updir" ] || updir="/var/cache/uploads"
23 html_header "File Upload"
24 echo "<h1>File Upload</h1>"
25 cat << EOT
26 <div id="actions">
27 <form method="post" action="$script" enctype="multipart/form-data">
28 <input type="hidden" name="upload" />
29 <input type="file" name="file" size="50" />
30 <p><input type="submit" value="Upload to $(hostname)" /></p>
31 </form>
32 </div>
34 <h2>Default upload directory: $updir</h2>
35 <pre>
36 $(ls -l ${updir})
37 </pre>
38 EOT
39 html_footer && exit 0
40 fi