in reply to Perl Upload with JQuery

Line 20 of your Perl creates a handle for a file named "new_filetxt" -- not a handle for a file named "new_file.txt" (i.e. filename dot extension) as you apparently intended.

Inside (despite!) the double quotes, open my $NEWFILE_FH, "+>", "$web_home/tmp/$newfilename.txt" concatenates "txt" to "new_file":

perl -e "my $filename = "new_file"; my $var ="$filename.txt"; print $v +ar;" new_filetxt

And the error message in "or die "Problems creating file '$newfilename': $!"; misleadingly reports an inability to create a file of a different name, "new_file."

Update: Fixed typo in para1, s/"new_filetext"/"new_filetxt"/;

Update2: My VERY bad; tested at a w32 CLI and forgot that Mr. Gates prodigy would not correct my failure to escape the interior double quotes. Sorry for inconveniencing all those electrons... and for my error!

Replies are listed 'Best First'.
Re^2: Perl Upload with JQuery
by Anonymous Monk on Dec 08, 2010 at 19:11 UTC
    I am sending to this other Perl script from the html form, but still can't get the file to upload:
    #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw ( fatalsToBrowser ); use File::Basename; my $safe_filename_characters = "a-zA-Z0-9_.-"; my $upload_dir = "/upfiles"; my $query = new CGI; my $filename = $query->param("file"); my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); $filename = $name . $extension; $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g; if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters"; } my $upload_filehandle = $query->upload("file"); open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; while ( <$upload_filehandle> ) { print UPLOADFILE "$_"; } close UPLOADFILE; ##this is the only way to send msg back to the client print "<script>parent.callback('upload file success')</script>"; exit;