Re: [pgsql-ayuda] Large objects

From: Victor Manuel Jaquez Leal <ceyusa(at)coral(dot)com(dot)mx>
To: pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: Re: [pgsql-ayuda] Large objects
Date: 2000-03-22 01:07:08
Message-ID: Pine.LNX.4.21.0003211902110.718-101000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

> esto para el web, esto es un usuario sube su archivo en texto via una
> pagina web, se guarda en la base de datos, y posteriormente el sistema
> puede desplegarlo en una pagina web.
>
> Alguna idea de como hacer esto???

¿Qué te parece esta función en Perl?
La utilizo para subir imágenes, pero puedes cambiar la validación del tipo
MIME para el tipo que desees subir.

Por cierto es parte de un módulo Perl que jalo de módulos mod-perl.

$UPLOAD_SIZE_LIMIT = 50 * 1024; # 50K

$IMG_DIR = "/www/galeria/usr";
$TMP_DIR = "/tmp";

use MIME::Parser;

sub receive_upload {
my ($r, $uid, $data) = @_;

my $size = $r->header_in("Content-Length");
$r->warn("Upload Size: $size");
if ($size > $UPLOAD_SIZE_LIMIT) {
return "Error: The file size exceeds the limit ($UPLOAD_SIZE_LIMIT bytes)";
}
my $buffer;
my $didread = $r->read($buffer, $size);
if ($didread != $size) {
return "Error: client failed to upload correct data size";
}
# $r->warn("Raw data: \n$buffer");
my $parser = MIME::Parser->new(output_to_core => "ALL");
$buffer =~ /^--(.*)\r\n/
or return "Error: Badly formatted MIME form from client";
$buffer = "Content-Type: multipart/form-data;boundary=$1\r\n\r\n$buffer";
my $ent = $parser->parse_data(\$buffer);
$buffer = "";
my $num = $ent->parts;
# $r->warn("$num MIME parts"); # debug
for (my $i = 0; $i < $num; $i++) {
my $part = $ent->parts($i);
my $name = $part->head->mime_attr("content-disposition.name");
my $type = $part->head->mime_type;
# $r->warn("part $i name=$name filename=$file type=$type"); #debug
if ($type =~ /^image/) {
my $file = get_filename($part->head->mime_attr("content-disposition.filename"));
my $user = get_username($uid);
$data->{$name} = $file;
# $r->warn("$IMG_DIR/$user/$file"); # debug
open FILE, ">$IMG_DIR/$user/$file" ||
return "Error: Can't create the image file";
$part->bodyhandle->print(\*FILE);
close FILE;
} elsif ($type =~ /^text/) {
$data->{$name} = $part->bodyhandle->as_string;
$r->warn("$name = $data->{$name}"); # debug
} else {
return "Error: invalid MIME type";
}
}
1;
}

----------------------------------
Víctor Manuel Jáquez Leal
ceyusa(at)coral(dot)com(dot)mx
http://www.coral.com.mx/ceyusa
+52 (4) 614-33-03

Attachment Content-Type Size
null application/octet-stream 0 bytes

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Ing. Roberto Andrade Fonseca 2000-03-22 01:10:28 [pgsql-ayuda] Traduccion de documentacion de pgsql
Previous Message Juan Manuel Rivero M. 2000-03-21 23:13:31 [pgsql-ayuda] Large objects