?
Solved

file

Posted on 2006-05-11
5
Medium Priority
?
181 Views
Last Modified: 2013-12-25
file upload...i m trying to upload client's file on server


#!c:/perl/bin/Perl.exe
use CGI;

print "Content-type: text/html; charset=iso-8859-1\n\n";
$|=1;

print "Upload File.........\n";
$query = new CGI;
$filename = $query->param("upload_file");
print "$filename  : <br>";
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("upload_file");
$upload_dir = "C:\\file.txt";

open UPLOADFILE, ">$upload_dir";
#binmode UPLOADFILE;
 while ( <$upload_filehandle> )
 {
   print UPLOADFILE;
 }
 close UPLOADFILE;


it does create the file c:\file.txt on server, but the file is empty, when menas the script is not able to read clients file...
Any ideas, why?
is it due to some apache configuration?
0
Comment
Question by:perlperl
  • 4
5 Comments
 

Author Comment

by:perlperl
ID: 16661945
i guess i have to change the header
print "Content-type: text/html; charset=iso-8859-1\n\n";  to read the clients file (just guessing....)
because right now its not even going in the while loop
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 2000 total points
ID: 16663335
You need to use a multi part form

use CGI;

print $query->header(); # it is easier to creat HTML headers with these CGI methods
print $query->start_html();

print $query->start_multipart_form(),
      "File to upload:",
      $query->filefield(-name=>'upload_file',  -size=>40),  # let user pick a lcoal file
      p,
      $query->submit(-name=>'submit',  -value=>'Upload File'),
      $query->endform,
      $query->end_html;

# now form is submitted and file transferred you can save file locally

print "Upload File.........\n";
$query = new CGI;
$filename = $query->param("upload_file");
print "$filename  : <br>";
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("upload_file");
$upload_dir = "C:\\file.txt";

open UPLOADFILE, ">$upload_dir";
#binmode UPLOADFILE;
 while ( <$upload_filehandle> )
 {
   print UPLOADFILE;
 }
 close UPLOADFILE;
0
 

Author Comment

by:perlperl
ID: 16667128
but where exactly are you redirecting the page...i mean theris nothing like "action = blah...cgi"
0
 

Author Comment

by:perlperl
ID: 16667296
i got it
print $query->start_multipart_form(-action=>"hkshfk.cgi"),

0
 

Author Comment

by:perlperl
ID: 16667992
but how do i create the fancy html like tables....initially my form elements were in tables
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question