Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Upload file format checking

Reply
Thread Tools

Upload file format checking

 
 
Bryan
Guest
Posts: n/a
 
      03-02-2006
Hi,

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?

Suggestions for implementations?

Thanks,
B
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-02-2006
Bryan <> wrote:
> Hi,
>
> 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?


That depends on what you plan to do about it if the file is not valid,
and what you plan to do with it if it is valid.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-02-2006
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. So my answer would be:
After you have stored it, and then delete the file if the validation fails.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Bryan
Guest
Posts: n/a
 
      03-02-2006
wrote:
> Bryan <> wrote:
>
>>Hi,
>>
>>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?

>
>
> That depends on what you plan to do about it if the file is not valid,
> and what you plan to do with it if it is valid.
>
> Xho
>


Dont really see how that matters as that is another function. Maybe Ill
delete it. Maybe Ill fire a js message, maybe Ill fix it.

But I think a yes or no would be sufficient, a function that returns a 1
or 0.
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-02-2006
Bryan <> wrote in
news:57tNf.55611$. com:

> wrote:
>> Bryan <> wrote:
>>
>>>Hi,
>>>
>>>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?

>>
>>
>> That depends on what you plan to do about it if the file is not
>> valid, and what you plan to do with it if it is valid.
>>
>> Xho
>>

>
> Dont really see how that matters as that is another function. Maybe
> Ill delete it. Maybe Ill fire a js message, maybe Ill fix it.
>
> But I think a yes or no would be sufficient, a function that returns a
> 1 or 0.


Are you somehow expecting that someone is going to write that for you?

Sinan

--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-02-2006
Bryan <> wrote:
> wrote:
> > Bryan <> wrote:
> >
> >>Hi,
> >>
> >>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?

> >
> >
> > That depends on what you plan to do about it if the file is not valid,
> > and what you plan to do with it if it is valid.
> >
> > Xho
> >

>
> Dont really see how that matters as that is another function.


If you are only interested in throwing the problem over the wall and then
forgetting about, why ask which way is best? It seems like, at this point,
it is all the same to you.

> Maybe Ill
> delete it.


Well, then I guess you had better save it to disk first. Or else deleting
will be pretty hard.

> Maybe Ill fire a js message, maybe Ill fix it.


I doubt you will be firing off a js message on the server.

>
> But I think a yes or no would be sufficient, a function that returns a 1
> or 0.


If that is sufficient, that what is your question?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Rick Scott
Guest
Posts: n/a
 
      03-02-2006
(Bryan <> uttered
> 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?
>
> Suggestions for implementations?


Have you searched CPAN? Does Text::TabFile do most of what you need?




Rick
--
key CF8F8A75 / print C5C1 F87D 5056 D2C0 D5CE D58F 970F 04D1 CF8F 8A75
ADMIRATION, n. Our polite recognition of another's resemblance to
ourselves.
:Ambrose Bierce, "The Devil's Dictionary" (1911)
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      03-05-2006
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).

hp
--
This is not a signature
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-05-2006
"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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload from client application (non-form based upload) stuart@microsoft.com Python 1 11-25-2006 12:14 AM
Upload a file without file Upload control - ASP.Net =?Utf-8?B?U2FyYXY=?= ASP .Net 3 08-03-2005 01:09 AM
is there a way of checking the size of the file before an upload begins Mel HTML 4 11-23-2004 12:21 AM
How to detect sizeof upload in order to show status of browser file upload? Heather Fraser Java 0 07-05-2004 12:35 AM
Checking file upload size Vicky ASP .Net 1 02-11-2004 09:51 AM



Advertisments