Solved

uploading and downloading files

Posted on 2000-02-21
5
185 Views
Last Modified: 2010-03-05
how do i upload and down load files using perl( in a Web application) giving the user the option to choose file(s) from a directory(location)...????
0
Comment
Question by:babykai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:KishoreS78
ID: 2543550
see Net::FTP module
u could play around with ftp transferring files.
0
 
LVL 1

Expert Comment

by:dmag
ID: 2544898
Please explain what you want in more detail. Is this a web application? Do you want to use FTP? or what?
0
 
LVL 3

Expert Comment

by:alien_life_form
ID: 2545209
Greetings.

If this is a web application:

i) for downloading, you need nothing more than a link to the appropriate file.

ii) For uploading, you can use CGI.pm, taking advantage of its multipart form support- it will do exactly what you want, from within a browser. CGI.pm's documentation is bundled with perl.

Cheers,
   alf
0
 

Author Comment

by:babykai
ID: 2545377
Edited text of question.
0
 

Accepted Solution

by:
baralong earned 10 total points
ID: 2567929
To upload the file you need something like:

<form enctype="multipart/form-data" action="http://server/accept.pl" method="post">
<input name="my_file" type="file">
</form>

Most browsers implement the the input type="file" tag with a button the brings up a file selector window.

In accept.pl have something like:

use CGI;
$query= new CGI;
$fileup = $query->param('my_file');

# extract its name
$strFilename = $fileup;
$strFilename =~ s/.*\\([^\s\\]+)$/$1/;

# build a name for the file on the server
$localFile =~ s/\\[^\s\\]+$//;
$localFile .= "\path\" . $strFilename;
 
# save the file
open (OUTFILE,">$localFile");
binmode($fileup);
binmode(OUTFILE);
while ($bytesread=read($fileup,$buffer,1024)) {
      print OUTFILE $buffer;
}

You will only need the binmode statements if the OS you are using diferentiates between text and binary files (eg windows, or at least the version that I'm using)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Uploading Binary Data using Perl 5 99
syslog unix file 20 80
Perl string replace for refred url 9 70
Insert Text into odbc.ini file 15 71
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

696 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