"Peter J. Holzer" <hjp-> wrote:
> Gunnar Hjalmarsson wrote:
> > Bryan wrote:
> >> What is the best way to validate that an uploaded file (using CGI.pm)
> >> is a tab delimited table of the correct format? I.e. every line has
> >> the same number of columns as the header, and the header has to match
> >> a predefined set of table headers. Should it be done as the file is
> >> read in? After I store it to disk?
> >
> > I don't understand how you would be able to validate the file before it
> > has been stored to disk, at least temporarily.
>
> You (or more exactly, the CGI module) are reading the contents of the
> file from stdin. In general, it is certainly possible to validate the
> contents as it is being read - it doesn't have to be stored at all.
> However, CGI stores the contents in a temporary file, so usually, when
> you get around to it, it is already on disk. But from reading the docs,
> it looks like upload_hook might be used to change that (I've never used
> it).
upload_hook lets you peek at the file-data while it is being saved to disk,
but doesn't let you peek at instead of it being written to disk.
But it is a fairly simple hack to make it work that way, something like:
if ($DISABLE_UPLOADS) {
while (defined($data = $buffer->read)) {
if (defined $self->{'.upload_hook'}) {
$totalbytes += length($data);
&{$self->{'.upload_hook'}}($filename ,$data,
$totalbytes, $self->{'.upload_data'});
}
}
last UPLOADS;
}
Xho
--
--------------------
http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB