You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Michael Boudreau <mb...@press.uchicago.edu> on 2002/03/18 17:31:38 UTC

file upload

I'm having a problem with a file upload when the "read" function is in an 
embperl fragment called by the "Execute" method.

Here's a simplified version of my main file:

--------------------------------------------
[$ if $fdat{choice} eq "choice1" $]

    [- Execute("frag1.epl"); -]

[$ elsif $fdat{choice} eq "choice2" $]

    [- Execute("frag2.epl"); -]

[$ endif $]
--------------------------------------------

The file "frag1.epl" contains this:

    [- if ( $fdat{UploadFile} ) {

          open (FILE, "> tmpfile.txt") or die "can't open: $!";
          print FILE $buffer while read($fdat{UploadFile}, $buffer, 32768);
          close (FILE) or die "can't close: $!";
       }
    -]

When I process the main file, I get a zero-length "tmpfile.txt", because 
there is apparently nothing for the "read" function to read.

However, if I move the "read" code out of frag1.epl and into the main file 
(just before the "Execute" statement), the upload works.

Any idea why this is happening?

=================================================
Michael Boudreau
Senior Electronic Publishing Developer
The University of Chicago Press
1427 E. 60th Street
Chicago, IL 60637-2954

phone: 773 753 3298
fax: 773 753 3383
================================================= 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: file upload

Posted by Gerald Richter <ri...@ecos.de>.
>version 1.3b7, according to the log

Oh, this is really old. You should upgrade to 1.3.4 ...

>But I want to be able to access %fdat values from inside frag1.epl.
Wouldn't this prevent me from doing that?

You can still access the data in %fdat, it's just not resetup (which doesn't
work) when the file is Executed

Gerald
-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: file upload

Posted by Gerald Richter <ri...@ecos.de>.
>
> I have 1.3.4 installed now, but it still appears that $fdat{UploadFile} is
> not accessible to the "read" function inside my code called by "Execute".
> However, if I set $UploadFile=$fdat{UploadFile}, then I can "read"
$UploadFile.
>

Then my guess that upgrading to 1.3.4 helps was wrong, but anyway it really
makes sense to upgrade.

CGI.pm uses some Perl magic to tie a filehandle and the filename to the same
variable (i.e.$fdat{UploadFile}), sometimes Perl doesn't handle this sort of
magic quite correct. Assigning it to a intermediate variable, as you done,
helps most the time. So I suggest, stay with your solution.


> This option
>
>    [- Execute({inputfile => "frag1.epl", options =>
>       HTML::Embperl::optDisableFormData}); -]
>
> doesn't work at all.
>

What mean's doesn't work at all? Do you get an error message, if yes what or
doesn't it change anything?

(If you upgraded to 1.3.4 it is not supposed to change anything, that was
just for the older versions)

Gerald

P.S. Please keep the thread on the list


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: file upload

Posted by Michael Boudreau <mb...@press.uchicago.edu>.
At 3/18/02 09:15 PM, Gerald Richter wrote:


> > I'm having a problem with a file upload when the "read" function is in an
> > embperl fragment called by the "Execute" method.
> >....
> >
> > When I process the main file, I get a zero-length "tmpfile.txt", because
> > there is apparently nothing for the "read" function to read.
> >
>
>Which Embperl version do you are using? If I remeber right this is a bug in
>older Embperl versions. 1.3.4 and 2.0b6 should work ok.

version 1.3b7, according to the log


>A workaround is to
>call the file which reads the data via
>
>
>
>     [- Execute({inputfile => "frag1.epl", options =>
>HTML::Embperl::optDisableFormData}); -]

But I want to be able to access %fdat values from inside frag1.epl. 
Wouldn't this prevent me from doing that?


=================================================
Michael Boudreau
Senior Electronic Publishing Developer
The University of Chicago Press
1427 E. 60th Street
Chicago, IL 60637-2954

phone: 773 753 3298
fax: 773 753 3383
================================================= 

Re: file upload

Posted by Michael Boudreau <mb...@press.uchicago.edu>.
That's not it. I'm able to access all the values of the %fdat hash from 
code within the fragment called by "Execute".

In fact, I can make the fragment display the name of the file uploaded from 
my desktop, but for some reason embperl can't "read" it.


At 3/18/02 12:58 PM, Ed Grimm wrote:
>frag1.epl runs in a different namespace, where %fdat does not exist.
>If you set EMBPERL_PACKAGE, it supposedly runs everything in that
>namespace, but I've not yet gotten flawless results with this (I'm doing
>a bunch of non-standard stuff; this could be my problem.)
>
>Ed
>
>On Mon, 18 Mar 2002, Michael Boudreau wrote:
>
> > I'm having a problem with a file upload when the "read" function is in an
> > embperl fragment called by the "Execute" method.
> >
> > Here's a simplified version of my main file:
> >
> > --------------------------------------------
> > [$ if $fdat{choice} eq "choice1" $]
> >
> >     [- Execute("frag1.epl"); -]
> >
> > [$ elsif $fdat{choice} eq "choice2" $]
> >
> >     [- Execute("frag2.epl"); -]
> >
> > [$ endif $]
> > --------------------------------------------
> >
> > The file "frag1.epl" contains this:
> >
> >     [- if ( $fdat{UploadFile} ) {
> >
> >           open (FILE, "> tmpfile.txt") or die "can't open: $!";
> >           print FILE $buffer while read($fdat{UploadFile}, $buffer, 32768);
> >           close (FILE) or die "can't close: $!";
> >        }
> >     -]
> >
> > When I process the main file, I get a zero-length "tmpfile.txt", because
> > there is apparently nothing for the "read" function to read.
> >
> > However, if I move the "read" code out of frag1.epl and into the main file
> > (just before the "Execute" statement), the upload works.
> >
> > Any idea why this is happening?
> >
> > =================================================
> > Michael Boudreau
> > Senior Electronic Publishing Developer
> > The University of Chicago Press
> > 1427 E. 60th Street
> > Chicago, IL 60637-2954
> >
> > phone: 773 753 3298
> > fax: 773 753 3383
> > =================================================
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> > For additional commands, e-mail: embperl-help@perl.apache.org
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
>For additional commands, e-mail: embperl-help@perl.apache.org


=================================================
Michael Boudreau
Senior Electronic Publishing Developer
The University of Chicago Press
1427 E. 60th Street
Chicago, IL 60637-2954

phone: 773 753 3298
fax: 773 753 3383
================================================= 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: file upload

Posted by Gerald Richter <ri...@ecos.de>.

> I'm having a problem with a file upload when the "read" function is in an
> embperl fragment called by the "Execute" method.
>....
>
> When I process the main file, I get a zero-length "tmpfile.txt", because
> there is apparently nothing for the "read" function to read.
>

Which Embperl version do you are using? If I remeber right this is a bug in
older Embperl versions. 1.3.4 and 2.0b6 should work ok. A workaround is to
call the file which reads the data via



    [- Execute({inputfile => "frag1.epl", options =>
HTML::Embperl::optDisableFormData}); -]

Gerald



-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: file upload

Posted by Gerald Richter <ri...@ecos.de>.

> frag1.epl runs in a different namespace, where %fdat does not exist.

No, %fdat (as all other special Embperl variables) are imported into all
Embperl pages, so it's the same regardless in which package you run

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: file upload

Posted by Ed Grimm <ed...@asgard.rsc.raytheon.com>.
frag1.epl runs in a different namespace, where %fdat does not exist.
If you set EMBPERL_PACKAGE, it supposedly runs everything in that
namespace, but I've not yet gotten flawless results with this (I'm doing
a bunch of non-standard stuff; this could be my problem.)

Ed

On Mon, 18 Mar 2002, Michael Boudreau wrote:

> I'm having a problem with a file upload when the "read" function is in an 
> embperl fragment called by the "Execute" method.
> 
> Here's a simplified version of my main file:
> 
> --------------------------------------------
> [$ if $fdat{choice} eq "choice1" $]
> 
>     [- Execute("frag1.epl"); -]
> 
> [$ elsif $fdat{choice} eq "choice2" $]
> 
>     [- Execute("frag2.epl"); -]
> 
> [$ endif $]
> --------------------------------------------
> 
> The file "frag1.epl" contains this:
> 
>     [- if ( $fdat{UploadFile} ) {
> 
>           open (FILE, "> tmpfile.txt") or die "can't open: $!";
>           print FILE $buffer while read($fdat{UploadFile}, $buffer, 32768);
>           close (FILE) or die "can't close: $!";
>        }
>     -]
> 
> When I process the main file, I get a zero-length "tmpfile.txt", because 
> there is apparently nothing for the "read" function to read.
> 
> However, if I move the "read" code out of frag1.epl and into the main file 
> (just before the "Execute" statement), the upload works.
> 
> Any idea why this is happening?
> 
> =================================================
> Michael Boudreau
> Senior Electronic Publishing Developer
> The University of Chicago Press
> 1427 E. 60th Street
> Chicago, IL 60637-2954
> 
> phone: 773 753 3298
> fax: 773 753 3383
> ================================================= 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org