06-16-2005
stuck in perl cgi to upload a file to server
hi,
i m working on a perl cgi script which uploads a file to the server. i m stuck. i hav written the errors.
plz help.
Sachin Kaw
______________________________________________________________________
#!/usr/bin/perl -w
use CGI;
use CGI qw(:standard);
use strict;
use POSIX qw(strftime);
use Spreadsheet::WriteExcel;
#use HTML::EasyTable;
use POSIX qw(tmpnam);
use CGI::Carp qw(carpout);
$CGI::POST_MAX=1024 * 5000; # max 5MB posts
my $logfile = "/tmp/upload-mylog.log";
BEGIN {
use CGI::Carp qw(carpout);
open(LOG, ">>/tmp/upload-cgi.log") or
die("Unable to open cgi.log: $!\n");
carpout(\*LOG);
}
# your custom running log function
sub mylog
{
my $curtime = strftime "%a %b %d %T", localtime;
my $curfunc = (caller(1))[3];
if( !defined $curfunc ){
$curfunc = "main:";
}
my $FL;
open( FL, ">>$logfile" ) || die "could not open file";
print FL "$curtime: $curfunc: $_[0]\n"; # This line prints to the log
close (FL);
}
my $q = new CGI;
#my $filename='filename';
my $upload_filehandle;
mylog ( "______ mylog ( __LINE__ . ": Before entering if block" );
if (param()) {
mylog ( __LINE__ . ": We have the form populated." );
# upload directory
my $upload_dir = "/home/skw";
# reading the form variables
my $filename = $q->param('filename');
mylog("filename = $filename");
$filename =~ s/.*[\/\\](.*)/$1/;
mylog("file = $filename");
# getting the file handle
$upload_filehandle = $q->upload('filename');
mylog("fd = $upload_filehandle"); #error 1
# saving the file
open (OUTFILE, ">$upload_dir/$filename");
#binmode UPLOADFILE;
while ( <$upload_filehandle> ) $error 2 & 3
{
print OUTFILE $_;
}
close OUTFILE;
print $q->header();
#print <<END_HTML;
}
else {
mylog ( __LINE__ . ": Form is not populated." );
#$strhtml .= $q->end_html;
}
___________________________________________________________________________
error 1:- Use of uninitialized value in <HANDLE>
error 2:- Use of uninitialized value in concatenation (.)
error 3:- readline() on unopened filehandle
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have an excel file with only 5 rows .I want to uplaod those 5 rows to a database using a shell script.Is this possible.If so where do i start.
Thnks (1 Reply)
Discussion started by: magikminox
1 Replies
2. Shell Programming and Scripting
Hi all
i have a such question this is my shell script my script must upload file to webdav server
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#!/bin/sh
###... (1 Reply)
Discussion started by: knut
1 Replies
3. IP Networking
I am using cgic lib to implement file upload, but the speed is very very slow... what is even worse, the file uploaded to my website is corrupted.
pakages captured by wireshark:
...
9606 56.258491 192.168.7.77 192.168.7.235 HTTP Continuation or non-HTTP traffic... (5 Replies)
Discussion started by: vistastar
5 Replies
4. Web Development
Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect.
Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is
redirected to welcome page.
My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies
5. Shell Programming and Scripting
Hello,
I have a script that finds the latest version of a file in a folder on my Minecraft server. I'm trying to come up with something that will then FTP that file over to my fileserver.
Here's what I have that finds the newest file:
find /home/mc/archive/sbhouse -type f -mtime +45 -exec... (7 Replies)
Discussion started by: nbsparks
7 Replies
6. Shell Programming and Scripting
Xperts,
My requirement is something like this,
I have a sql script which i need to embed in a shell. The sql (oracle) script will generate a .csv file in some Unix directory. the approximate file size is around 10 mb which i need to upload to an sftp server. My concern here is how to make... (5 Replies)
Discussion started by: Showdown
5 Replies
7. Shell Programming and Scripting
Hi team,
I have a typical problem with cgi pages in apache webserver in WINDOWS
I am able to execute(display) the pages that are saved in cgi-bin folder.
But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder.
Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies
8. Shell Programming and Scripting
Hi All,
I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet.
I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet.
print "<center><table... (2 Replies)
Discussion started by: scriptscript
2 Replies
9. Proxy Server
I have a requirement of following -
1. Transfer excel spreadsheet from desktop to unix server
2. Open the spreadsheet and read the sql row by row at a time
3. Run each sql on database using unix and then send output back to spreadsheet that was uploaded earlier and then transfer file back to... (12 Replies)
Discussion started by: Analabhatla
12 Replies
LEARN ABOUT DEBIAN
log::report::dispatcher::file
Log::Report::Dispatcher::File(3pm) User Contributed Perl Documentation Log::Report::Dispatcher::File(3pm)
NAME
Log::Report::Dispatcher::File - send messages to a file or file-handle
INHERITANCE
Log::Report::Dispatcher::File
is a Log::Report::Dispatcher
SYNOPSIS
dispatcher Log::Report::Dispatcher::File => 'stderr'
, to => *STDERR, accept => 'NOTICE-';
# close a dispatcher
dispatcher close => 'stderr';
# let dispatcher open and close the file
dispatcher FILE => 'mylog', to => '/var/log/mylog'
, charset => 'utf-8';
...
dispatcher close => 'mylog'; # will close file
# open yourself, then also close yourself
open OUT, ">:encoding('iso-8859-1')", '/var/log/mylog'
or fault "...";
dispatcher FILE => 'mylog', to => *OUT;
...
dispatcher close => 'mylog';
close OUT;
# dispatch into a scalar
my $output = '';
open $outfile, '>', $output;
dispatcher FILE => 'into-scalar', to => $outfile;
...
dispatcher close => 'into-scalar';
print $output;
DESCRIPTION
This basic file logger accepts an file-handle or filename as destination.
METHODS
Constructors
$obj->close
Only when initiated with a FILENAME, the file will be closed. In any other case, nothing will be done.
Log::Report::Dispatcher::File->new(TYPE, NAME, OPTIONS)
-Option --Defined in --Default
accept Log::Report::Dispatcher depend on mode
charset Log::Report::Dispatcher LOCALE
format_reason Log::Report::Dispatcher 'LOWERCASE'
locale Log::Report::Dispatcher <system locale>
mode Log::Report::Dispatcher 'NORMAL'
replace false
to <required>
accept => REASONS
charset => CHARSET
format_reason => 'UPPERCASE'|'LOWERCASE'|'UCFIRST'|'IGNORE'|CODE
locale => LOCALE
mode => 'NORMAL'|'VERBOSE'|'ASSERT'|'DEBUG'|0..3
replace => BOOLEAN
Only used in combination with a FILENAME: throw away the old file if it exists. Probably you wish to append to existing information.
Use the LOCALE setting by default, which is LC_CTYPE or LC_ALL or LANG (in that order). If these contain a character-set which Perl
understands, then that is used, otherwise silently ignored.
to => FILENAME|FILEHANDLE|OBJECT
You can either specify a FILENAME, which is opened in append mode with autoflush on. Or pass any kind of FILE-HANDLE or some OBJECT
which implements a "print()" method. You probably want to have autoflush enabled on your FILE-HANDLES.
When cleaning-up the dispatcher, the file will only be closed in case of a FILENAME.
Accessors
$obj->filename
Returns the name of the opened file, or "undef" in case this dispatcher was started from a file-handle or file-object.
$obj->isDisabled
See "Accessors" in Log::Report::Dispatcher
$obj->mode
See "Accessors" in Log::Report::Dispatcher
$obj->name
See "Accessors" in Log::Report::Dispatcher
$obj->needs
See "Accessors" in Log::Report::Dispatcher
$obj->type
See "Accessors" in Log::Report::Dispatcher
Logging
$obj->collectLocation
Log::Report::Dispatcher::File->collectLocation
See "Logging" in Log::Report::Dispatcher
$obj->collectStack([MAXDEPTH])
Log::Report::Dispatcher::File->collectStack([MAXDEPTH])
See "Logging" in Log::Report::Dispatcher
$obj->log(HASH-of-OPTIONS, REASON, MESSAGE)
See "Logging" in Log::Report::Dispatcher
$obj->stackTraceLine(OPTIONS)
Log::Report::Dispatcher::File->stackTraceLine(OPTIONS)
See "Logging" in Log::Report::Dispatcher
$obj->translate(HASH-of-OPTIONS, REASON, MESSAGE)
See "Logging" in Log::Report::Dispatcher
SEE ALSO
This module is part of Log-Report distribution version 0.94, built on August 23, 2011. Website: http://perl.overmeer.net/log-report/
LICENSE
Copyrights 2007-2011 by Mark Overmeer. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See
http://www.perl.com/perl/misc/Artistic.html
perl v5.14.2 2011-08-23 Log::Report::Dispatcher::File(3pm)