I have a problem using the upload method from CGI.
I am getting an undefined filehandle
Use of uninitialized value in <HANDLE>
I don't have problems retrieving the parameters from the ajax and creating the folder and the file (an empty one)
The problem is I cannot read from the filehandle.
Any suggestions how to solve this.
Thanks for your time and help!
<link rel="stylesheet" href="jquery.jgrowl.css" type="text/css"/> <!-- jQuery Library --> <script type="text/javascript" language="javascript" src="jquery-1.2.6 +.js"></script> <script type="text/javascript" language="javascript" src="jquery.jgrow +l.js"></script> <script type="text/javascript" language="javascript" src="test_ajax.js +"></script> <input type=file id=test> <div id=output></div>
$(document).ready(function () { $("#test").change(function(){ alert($(this).val()); var info = $.trim($(this).val()); $.ajax({ type: "POST", url: "/cgi-bin/upload_and_check.cgi", data: "filename="+info+"&session_id=abc", success: function(msg){ alert("This is the message: " + msg); $("#output").html(msg); $.jGrowl(msg, { sticky: true }); } }); }); });
#!/usr/bin/perl use warnings; use strict; use CGI; my $form = new CGI; print $form->header; #Print HTML header my $web_home = "$ENV{DOCUMENT_ROOT}/ajax"; #Getting parametres from form my $session_id = $form->param("session_id"); my $filename = $form->param("filename"); #Create temp dir if doesn't exist yet umask 0000; if ( !-e "$web_home/tmp/$session_id" ) { mkdir "$web_home/tmp/$session_id", 0777 or die "Problems creating temporary dir '$web_home/tmp/$sessi +on_id': $!\n"; } #the upload() method to grab the file handle my $UPLOAD_FH = $form->upload("filename"); my $newfilename = $session_id; open my $NEWFILE_FH, "+>", "$web_home/tmp/$session_id/$newfilename.txt +" or die "Problems creating file '$newfilename': $!"; while ( <$UPLOAD_FH> ) { print $NEWFILE_FH; } close $NEWFILE_FH or die "I cannot close filehandle: $!"; exit;
In reply to CGI upload from ajax by flope004
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |