WebGUI 2.7.0 release
This commit is contained in:
parent
c0463670e8
commit
08b81c6064
104 changed files with 7333 additions and 2576 deletions
89
lib/WebGUI/Attachment.pm
Normal file
89
lib/WebGUI/Attachment.pm
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package WebGUI::Attachment;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use File::Copy cp;
|
||||
use File::Path;
|
||||
use FileHandle;
|
||||
use POSIX;
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Utility;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# eg: copy(filename,oldWidgetId,newWidgetId,oldSubId,newSubId);
|
||||
sub copy {
|
||||
my ($a, $b, $newFile, $oldFile);
|
||||
if ($_[0] ne "") {
|
||||
$oldFile = $session{setting}{attachmentDirectoryLocal}.'/'.$_[1];
|
||||
if ($_[3] ne "") {
|
||||
$oldFile .= '/'.$_[3]
|
||||
}
|
||||
$oldFile .= '/'.$_[0];
|
||||
$newFile = $session{setting}{attachmentDirectoryLocal}.'/'.$_[2];
|
||||
if ($_[4] ne "") {
|
||||
$newFile .= '/'.$_[4]
|
||||
}
|
||||
mkdir ($newFile,0755);
|
||||
$newFile .= '/'.$_[0];
|
||||
$a = FileHandle->new($oldFile,"r");
|
||||
$b = FileHandle->new(">".$newFile);
|
||||
cp($a,$b);
|
||||
$a->close;
|
||||
$b->close;
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purgeWidget {
|
||||
my ($dir);
|
||||
$dir = $session{setting}{attachmentDirectoryLocal}.'/'.$_[0];
|
||||
rmtree($dir);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# eg: save(formVarName,widgetId,optionallySubmissionId);
|
||||
sub save {
|
||||
my ($file, $filename, $bytesread, $buffer, $urlizedFilename, $path);
|
||||
$filename = $session{cgi}->upload($_[0]);
|
||||
if (defined $filename) {
|
||||
if ($filename =~ /([^\/\\]+)$/) {
|
||||
$urlizedFilename = $1;
|
||||
} else {
|
||||
$urlizedFilename = $filename;
|
||||
}
|
||||
$urlizedFilename = urlize($urlizedFilename);
|
||||
$path = $session{setting}{attachmentDirectoryLocal}."/".$_[1]."/";
|
||||
mkdir ($path,0755);
|
||||
if ($_[2] ne "") {
|
||||
$path = $path.$_[2].'/';
|
||||
mkdir ($path,0755);
|
||||
}
|
||||
$file = FileHandle->new(">".$path.$urlizedFilename);
|
||||
if (defined $file) {
|
||||
binmode $file;
|
||||
while ($bytesread=read($filename,$buffer,1024)) {
|
||||
print $file $buffer;
|
||||
}
|
||||
close($file);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
return $urlizedFilename;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue