[pgsql-ayuda] Large objects

Victor Manuel Jaquez Leal ceyusa@coral.com.mx
Tue, 21 Mar 2000 19:07:08 -0600 (CST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--8323328-174457315-953687228=:718
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by localhost.localdomain id TAA00730

> 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.
>=20
> Alguna idea de como hacer esto???

=BFQu=E9 te parece esta funci=F3n en Perl?
La utilizo para subir im=E1genes, pero puedes cambiar la validaci=F3n del=
 tipo
MIME para el tipo que desees subir.

Por cierto es parte de un m=F3dulo Perl que jalo de m=F3dulos mod-perl.

$UPLOAD_SIZE_LIMIT =3D 50 * 1024;  # 50K

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

use MIME::Parser;

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

    my $size =3D $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 =3D $r->read($buffer, $size);
    if ($didread !=3D $size) {
	return "Error: client failed to upload correct data size";
    }
    # $r->warn("Raw data: \n$buffer");
    my $parser =3D MIME::Parser->new(output_to_core =3D> "ALL");
    $buffer =3D~ /^--(.*)\r\n/=20
	or return "Error: Badly formatted MIME form from client";
    $buffer =3D "Content-Type: multipart/form-data;boundary=3D$1\r\n\r\n$=
buffer";
    my $ent =3D $parser->parse_data(\$buffer);
    $buffer =3D "";
    my $num =3D $ent->parts;
    # $r->warn("$num MIME parts"); # debug
    for (my $i =3D 0; $i < $num; $i++) {
	my $part =3D $ent->parts($i);
	my $name =3D $part->head->mime_attr("content-disposition.name");
	my $type =3D $part->head->mime_type;
	# $r->warn("part $i name=3D$name filename=3D$file type=3D$type"); #debug
	if ($type =3D~ /^image/) {
	    my $file =3D get_filename($part->head->mime_attr("content-dispositio=
n.filename"));
	    my $user =3D get_username($uid);
	    $data->{$name} =3D $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 =3D~ /^text/) {
	    $data->{$name} =3D $part->bodyhandle->as_string;
	    $r->warn("$name =3D $data->{$name}"); # debug
	} else {
	    return "Error: invalid MIME type";
	}
    }	   =20
    1;
}

----------------------------------
V=EDctor Manuel J=E1quez Leal
ceyusa@coral.com.mx
http://www.coral.com.mx/ceyusa
+52 (4) 614-33-03

--8323328-174457315-953687228=:718
Content-Type: APPLICATION/octet-stream; name=null
Content-ID: <Pine.LNX.4.21.0003211907080.718@localhost.localdomain>
Content-Description: 
Content-Disposition: attachment; filename=null
Content-Transfer-Encoding: BASE64


--8323328-174457315-953687228=:718--
--------- Pie de mensaje -------------------------------------------
Archivo historico: http://tlali.iztacala.unam.mx/maillist/pgsql-ayuda
Cancelar inscripcion:
mail to: majordomo@tlali.iztacala.unam.mx
text   : unsubscribe pgsql-ayuda