The UNIX and Linux Forums  
Hello and Welcome from to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Mandriva: Updated x11-server packages fix stuck keys in Wine iBot Security Advisories (RSS) 0 05-27-2008 10:40 AM
How to upload a file into 2 servers at the same time. kcpriya UNIX for Dummies Questions & Answers 7 04-10-2008 04:20 AM
Perl sql table upload variable problem maheshsri Shell Programming and Scripting 2 12-01-2006 10:53 AM
How to upload to the unix server? rdog157h UNIX for Dummies Questions & Answers 4 01-01-2005 09:50 PM
Changing file permissions on upload guix UNIX for Advanced & Expert Users 6 07-13-2004 05:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-16-2005
sachin_kaw sachin_kaw is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 2
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
  #2 (permalink)  
Old 06-16-2005
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
I'm uncertain about file uploads. I previously made one in a similar manner with the CGI module and it worked on my system. A wild guess ... Your form has a file upload control with the name exactly as 'filename'? And does the $filename return some valid filename? Also verify that the permission of your upload directory is writable by the webserver running the script. Check the CGI module doc for possible locations the module will try for the upload spooling directories.
  #3 (permalink)  
Old 06-18-2005
sachin_kaw sachin_kaw is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 2
again stuck

yes,my form has a file upload control with the name exactly as 'filename'.

yes, $filename retuns a valid filename.

yes, the permission of your upload directory is writable by the webserver running the script.

inspite of all this, my script is still not working.

the problem is with the file handler. the script is not reading the file through the file handler.
Do i have to include any module to use the file handler?

plz help
  #4 (permalink)  
Old 06-18-2005
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Normally that should be it. Because what upload() returns is a filehandle you should be able to read it right away (provided a valid filehandle is returned). But now obviously the filehandle is undef. That was why I tried to make the guess that probably your temporary directory could not be written into, and so cannot be open()ed so no valid filehandle is returned.

Try this. Log the output of

$q->cgi_error

as the program proceeds. See if you get any error messages before or around the upload() method.
  #5 (permalink)  
Old 06-26-2005
ErNci ErNci is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 24
#my $filename='filename';
###$filename isnt set here (as it's commented out), nor anywhere else so.....

this means $filename =~ s/.*[\/\\](.*)/$1/; will fail as $filename isnt initilized.

And so

open (OUTFILE, ">$upload_dir/$filename"); cant open a valid handle

so when it writes handle is invalid.

Tip: try using open (OUTFILE, ">$upload_dir/$filename") or die ($!);

AAR.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0