I'm trying to upload a file from a form, but in IE and Firefox it is giving me an error (in Safari for Mac it works just fine):

Can't call method "fh" on an undefined value



The code of the component for uploading the file is:


-------------------------------
<%args>
$newfile
</%args>
<%init>
$newfile =~ s/\ /_/xig;
$newfile =~ s/\,|\:|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\{|\[|\}|\]|\;|\'| \"|\?|\>|\<//xig;

my $dir = "/home/webtree/home/www.mydomain.com/html/files/";
my $filePath = time() . "_" . $newfile;

my $fullPath = $dir . $filePath;
my $http_path = 'http://www.mydomain.com/files/' . $filePath;

# create an Apache::Upload object
my $upload = $r->upload;

# get a filehandle for the uploaded file
my $upload_fh = $upload->fh;

open UPLOADFILE, ">$fullPath";
binmode UPLOADFILE;
print UPLOADFILE <$upload_fh>;
close($upload_fh);
close UPLOADFILE;

return $http_path;
</%init>
-------------------------------

And the code from the page that calls it...

-------------------------------
<%args>
$newfile    => undef
</%args>
<%init>

my $file_path;

if ($newfile) {
    $file_path = $m->comp("/i/uploadFile.mas", newfile=>$newfile);
}

if ($file_path) {
    $m->print("File is $file_path");
}
</%init>

<form method="post" action="/i/testUpload.html" enctype="multi-part/ form-data">
Upload File<br>
<input type="file" name="newfile">

<br><br>
<input type="submit" value="Upload">
</form>
-------------------------------


Any ideas on what would cause the problem? It's weird that it works for Safari, but not for IE/Firefox on Windows, or even Firefox on Mac.

If you don't know how to fix it, do you have any sample code for doing the same thing???

Thanks

-Michael
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to