diff options
author | Friendika <info@friendika.com> | 2011-01-26 00:34:39 -0800 |
---|---|---|
committer | Friendika <info@friendika.com> | 2011-01-26 00:34:39 -0800 |
commit | 2fc89deaeae0341aa12b6b811927e793011055d1 (patch) | |
tree | 32673c6b92cbe14f88d955de585ce813988ec5fa /addon/js_upload/file-uploader/server/perl.cgi | |
parent | abbd498a8b6c92ddcf211a27dd532f2ec6520fe2 (diff) | |
download | volse-hubzilla-2fc89deaeae0341aa12b6b811927e793011055d1.tar.gz volse-hubzilla-2fc89deaeae0341aa12b6b811927e793011055d1.tar.bz2 volse-hubzilla-2fc89deaeae0341aa12b6b811927e793011055d1.zip |
work in progress js_uploader plugin, turn java uploader into plugin - not done yet
Diffstat (limited to 'addon/js_upload/file-uploader/server/perl.cgi')
-rw-r--r-- | addon/js_upload/file-uploader/server/perl.cgi | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/addon/js_upload/file-uploader/server/perl.cgi b/addon/js_upload/file-uploader/server/perl.cgi new file mode 100644 index 000000000..c66f1aa1a --- /dev/null +++ b/addon/js_upload/file-uploader/server/perl.cgi @@ -0,0 +1,62 @@ +#!/usr/bin/perl + + use strict; + use CGI::Carp qw(fatalsToBrowser); + + use Digest::MD5; + + my $uploaddir = '/folder/to/save/in/ajax_upload/tmp_uploads'; + + my $maxFileSize = 0.5 * 1024 * 1024; # 1/2mb max file size... + + use CGI; + my $IN = new CGI; + + my $file = $IN->param('POSTDATA'); + my $temp_id = $IN->param('temp_id'); + + # make a random filename, and we guess the file type later on... + my $name = Digest::MD5::md5_base64( rand ); + $name =~ s/\+/_/g; + $name =~ s/\//_/g; + + my $type; + if ($file =~ /^GIF/) { + $type = "gif"; + } elsif ($file =~ /PNG/) { + $type = "png"; + } elsif ($file =~ /JFIF/) { + $type = "jpg"; + } + + if (!$type) { + print qq|{ "success": false, "error": "Invalid file type..." }|; + print STDERR "file has been NOT been uploaded... \n"; + } + + print STDERR "Making dir: $uploaddir/$temp_id \n"; + + mkdir("$uploaddir/$temp_id"); + + open(WRITEIT, ">$uploaddir/$name.$type") or die "Cant write to $uploaddir/$name.$type. Reason: $!"; + print WRITEIT $file; + close(WRITEIT); + + my $check_size = -s "$uploaddir/$name.$type"; + + print STDERR qq|Main filesize: $check_size Max Filesize: $maxFileSize \n\n|; + + print $IN->header(); + if ($check_size < 1) { + print STDERR "ooops, its empty - gonna get rid of it!\n"; + print qq|{ "success": false, "error": "File is empty..." }|; + print STDERR "file has been NOT been uploaded... \n"; + } elsif ($check_size > $maxFileSize) { + print STDERR "ooops, its too large - gonna get rid of it!\n"; + print qq|{ "success": false, "error": "File is too large..." }|; + print STDERR "file has been NOT been uploaded... \n"; + } else { + print qq|{ "success": true }|; + + print STDERR "file has been successfully uploaded... thank you.\n"; + }
\ No newline at end of file |