[Gambas-user] Use of Request.Files in gb.web

José Luis Redrejo jredrejo at ...626...
Fri Sep 14 17:07:44 CEST 2007


2007/9/14, Benoit Minisini <gambas at ...1...>:
>
> On vendredi 14 septembre 2007, José Luis Redrejo wrote:
> > 2007/9/14, Benoit Minisini <gambas at ...1...>:
> > > On vendredi 14 septembre 2007, José Luis Redrejo wrote:
> > > > Hi, Benoît,
> > > > Fighting with gb.web and its lack of documentation,
> > > >  I'm trying to use Request.Files to get an uploaded file,  but I'm
> not
> > >
> > > able
> > >
> > > > to recover the file.
> > > > Could you give a few lines of code with an example? or just a tip to
> > > > can
> > >
> > > go
> > >
> > > > on...
> > > >
> > > > Regards.
> > >
> > > Of course:
> > >
> > > If in your form, you have the following file field:
> > >
> > > <form ...>
> > > ...
> > > <input type="file" name="filename">
> > > ...
> > > </form>
> > >
> > > then gb.web will store the uploaded file in the process temporary
> > > directory,
> > > and Request.Fields["filename"] will return the path to this temporary
> > > file.
> > >
> > > Of course your form must use method="post", and
> > > enctype="multipart/form-data".
> > >
> > > Is it clearer?
> >
> > I must be a little closed minded today.
> >
> > I'm using this code:
> >
> > PUBLIC SUB Main()
> > DIM directorio AS String
> >
> >
> >   directorio = Request.Path
> >     Response.Begin
> >
> >   SELECT CASE directorio
> >    CASE "/", ""
> >
> >       PRINT "<p><h3>" & ("Example") & "</h3><p>"
> >       PRINT "<form action=\"" & Application.root & "/enviar\"
> > method=\"POST\" enctype=\"multipart/form-data\">"
> >       PRINT "Archivo de datos: <input name=\"filename\"
> type=\"file\"><br>"
> >       PRINT "<input name=\"submit\" type=\"submit\">"
> >       PRINT "</form>"
> >
> >    CASE "/enviar", "/enviar/"
> >
> >       PRINT "sending"
> >       TRY PRINT "<p>Fields.Count=" & CString(Request.Fields.Count)
> >       TRY PRINT "<p>Fields[0]=" & Request.Fields[0]
> >       TRY PRINT "<p>Fields[filename]=" & Request.Fields["filename"]
> >
> >     END SELECT
> >
> > Response.End
> >
> > '----------------
> > And, after uploading the file, the web browser output is:
> > sending
> >
> > Fields.Count=2
> >
> > Fields[0]=filename
> > '---------------
> >
>
> You should see:
>
> Fields.Count=2
> Fields[0]=filename
> Fields[filename]=
>
> If the third line is missing, that means there is an error.
>

Checking gb.web component code, Fields is returned from the $aField variable
that's defined as a String[], so if it's an array, Fields["filename"] is not
possible, it needs an integer as index.
So, or there's a bug, or that's not to be used the way you remember ...



More information about the User mailing list