CREATE TABLE image (
id mediumint(8) unsigned NOT NULL auto_increment,
articleId integer not null,
- image varchar(64) DEFAULT '' NOT NULL,
+ image varchar(255) DEFAULT '' NOT NULL,
alt varchar(255) DEFAULT '[Image]' NOT NULL,
width smallint(5) unsigned,
height smallint(5) unsigned,
use DevHelp::Date qw(dh_parse_date dh_parse_sql_date);
use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
-our $VERSION = "1.004";
+our $VERSION = "1.005";
=head1 NAME
$imagename =~ tr/ //d;
$imagename =~ /([\w.-]+)$/ and $basename = $1;
- # create a filename that we hope is unique
- my $filename = time. '_'. $basename;
-
# for the sysopen() constants
use Fcntl;
my $imagedir = cfg_image_dir($cfg);
- # loop until we have a unique filename
- my $counter="";
- $filename = time. '_' . $counter . '_' . $basename
- until sysopen( OUTPUT, "$imagedir/$filename", O_WRONLY| O_CREAT| O_EXCL)
- || ++$counter > 100;
-
- fileno(OUTPUT) or die "Could not open image file: $!";
+ require DevHelp::FileUpload;
+ my $msg;
+ my ($filename, $fh) =
+ DevHelp::FileUpload->make_img_filename($imagedir, $basename, \$msg);
+ unless ($filename) {
+ $errors->{image} = $msg;
+ return;
+ }
+print STDERR "Gen filename '$filename'\n";
# for OSs with special text line endings
- binmode OUTPUT;
+ binmode $fh;
my $buffer;
no strict 'refs';
# read the image in from the browser and output it to our output filehandle
- print OUTPUT $buffer while read $image, $buffer, 1024;
+ print $fh $buffer while read $image, $buffer, 1024;
# close and flush
- close OUTPUT
+ close $fh
or die "Could not close image file $filename: $!";
use Image::Size;
Table image
Column id;mediumint(8) unsigned;NO;NULL;auto_increment
Column articleId;int(11);NO;NULL;
-Column image;varchar(64);NO;;
+Column image;varchar(255);NO;;
Column alt;varchar(255);NO;[Image];
Column width;smallint(5) unsigned;YES;NULL;
Column height;smallint(5) unsigned;YES;NULL;